diff options
| author | Kalle Lindström <karl.lindstrom@mullvad.net> | 2025-02-25 10:48:50 +0100 |
|---|---|---|
| committer | Kalle Lindström <karl.lindstrom@mullvad.net> | 2025-02-26 09:25:17 +0100 |
| commit | da304ffedf8f8d98600f31f737cf92768c0323fa (patch) | |
| tree | e8da9b9a861f3d3efbbbc39fb5160ec1cfeb67fa /android/lib/common/src | |
| parent | 5025db74b34cfb3536c43f89f3407ffc0d97ae73 (diff) | |
| download | mullvadvpn-da304ffedf8f8d98600f31f737cf92768c0323fa.tar.xz mullvadvpn-da304ffedf8f8d98600f31f737cf92768c0323fa.zip | |
Remove Joda Time and use java.time package instead
Joda Time has been superseded by the Java 8 java.time package
which has more or less the same API. This commit removes all
usage of Joda Time and replaces it with the java.time classes.
This is done so that we can remove the dependency on Joda Time.
Diffstat (limited to 'android/lib/common/src')
2 files changed, 20 insertions, 14 deletions
diff --git a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonStringExtensions.kt b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonStringExtensions.kt index 536fea3d24..e34bfa582e 100644 --- a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonStringExtensions.kt +++ b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonStringExtensions.kt @@ -1,22 +1,8 @@ package net.mullvad.mullvadvpn.lib.common.util -import org.joda.time.DateTime -import org.joda.time.format.DateTimeFormat - -private const val EXPIRY_FORMAT = "YYYY-MM-dd HH:mm:ss z" private const val BIG_DOT_CHAR = "●" private const val SPACE_CHAR = ' ' -fun String.parseAsDateTime(): DateTime? { - return try { - DateTime.parse(this, DateTimeFormat.forPattern(EXPIRY_FORMAT)) - } catch (ex: IllegalArgumentException) { - null - } catch (ex: UnsupportedOperationException) { - null - } -} - fun String.groupWithSpaces(groupCharSize: Int = 4): String { return fold(StringBuilder()) { formattedText, nextDigit -> if ((formattedText.length % (groupCharSize + 1)) == groupCharSize) { diff --git a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/DateExtensions.kt b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/DateExtensions.kt new file mode 100644 index 0000000000..74fe9d6ba0 --- /dev/null +++ b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/DateExtensions.kt @@ -0,0 +1,20 @@ +package net.mullvad.mullvadvpn.lib.common.util + +import java.time.Duration +import java.time.Instant +import java.time.ZonedDateTime +import java.time.format.DateTimeFormatter +import java.time.format.FormatStyle + +fun ZonedDateTime.formatDate(): String = DateTimeFormatter.ISO_LOCAL_DATE.format(this) + +fun ZonedDateTime.toExpiryDateString(): String = + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).format(this) + +fun ZonedDateTime.millisFromNow(): Long = Duration.between(ZonedDateTime.now(), this).toMillis() + +fun ZonedDateTime.daysFromNow(): Long = Duration.between(ZonedDateTime.now(), this).toDays() + +fun ZonedDateTime.isBeforeNowInstant(): Boolean = toInstant().isBefore(Instant.now()) + +fun ZonedDateTime.isAfterNowInstant(): Boolean = toInstant().isAfter(Instant.now()) |
