Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Reduce the time range by 10 years to be safe
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Aug 28, 2024
1 parent cc76a70 commit 4a50cf4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class StandardTimeConverter @Inject constructor(
} catch (e: DateTimeException) {
// This happens when we overflow MIN/MAX for LocalDateTime
if (this > Instant.EPOCH) {
LocalDateTime.MAX
LocalDateTime.MAX.minusYears(10)
} else {
LocalDateTime.MIN
LocalDateTime.MIN.plusYears(10)
}
}

Expand All @@ -30,9 +30,9 @@ class StandardTimeConverter @Inject constructor(
} catch (e: DateTimeException) {
// This happens when we overflow MIN/MAX for LocalDate
if (this > Instant.EPOCH) {
LocalDate.MAX
LocalDate.MAX.minusYears(10)
} else {
LocalDate.MIN
LocalDate.MIN.plusYears(10)
}
}

Expand Down
38 changes: 0 additions & 38 deletions temp/legacy-code/src/main/java/com/ivy/legacy/utils/DateExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -256,44 +256,6 @@ fun LocalDate.formatLocal(
)
}

fun LocalDateTime.timeLeft(
from: LocalDateTime = timeNowUTC(),
daysLabel: String = "d",
hoursLabel: String = "h",
minutesLabel: String = "m",
secondsLabel: String = "s"
): String {
val timeLeftMs = this.millis() - from.millis()
if (timeLeftMs <= 0) return stringRes(R.string.expired)

val days = TimeUnit.MILLISECONDS.toDays(timeLeftMs)
var timeLeftAfterCalculations = timeLeftMs - TimeUnit.DAYS.toMillis(days)

val hours = TimeUnit.MILLISECONDS.toHours(timeLeftAfterCalculations)
timeLeftAfterCalculations -= TimeUnit.HOURS.toMillis(hours)

val minutes = TimeUnit.MILLISECONDS.toMinutes(timeLeftAfterCalculations)
timeLeftAfterCalculations -= TimeUnit.MINUTES.toMillis(minutes)

val seconds = TimeUnit.MILLISECONDS.toSeconds(timeLeftAfterCalculations)

var result = ""
if (days > 0) {
result += "$days$daysLabel "
}
if (hours > 0) {
result += "$hours$hoursLabel "
}
if (minutes > 0) {
result += "$minutes$minutesLabel "
}
// if (seconds > 0) {
// result += "$seconds$secondsLabel "
// }

return result.trim()
}

fun startOfMonth(date: LocalDate, timeConverter: TimeConverter): Instant {
val startOfMonthLocal = date.withDayOfMonth(1).atStartOfDay()
return with(timeConverter) { startOfMonthLocal.toUTC() }
Expand Down

0 comments on commit 4a50cf4

Please sign in to comment.