-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
16 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/DateExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package net.mullvad.mullvadvpn.util | ||
|
||
import java.text.DateFormat | ||
import kotlin.time.Duration.Companion.milliseconds | ||
import kotlin.time.DurationUnit | ||
import org.joda.time.DateTime | ||
import org.joda.time.format.ISODateTimeFormat | ||
|
||
fun DateTime.formatDate(): String = ISODateTimeFormat.date().print(this) | ||
|
||
fun DateTime.toExpiryDateString(): String = | ||
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(this.toDate()) | ||
|
||
fun DateTime.daysFromNow() = | ||
(toInstant().millis - DateTime.now().toInstant().millis).milliseconds.toInt(DurationUnit.DAYS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 1 addition & 13 deletions
14
android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/AccountExpiry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,15 @@ | ||
package net.mullvad.mullvadvpn.model | ||
|
||
import android.os.Parcelable | ||
import kotlin.time.Duration.Companion.milliseconds | ||
import kotlin.time.DurationUnit | ||
import kotlinx.parcelize.Parcelize | ||
import org.joda.time.DateTime | ||
|
||
sealed class AccountExpiry : Parcelable { | ||
@Parcelize | ||
data class Available(val expiryDateTime: DateTime) : AccountExpiry() { | ||
override fun daysLeft(): Int = | ||
(expiryDateTime.toInstant().millis - DateTime.now().toInstant().millis) | ||
.milliseconds | ||
.toInt(DurationUnit.DAYS) | ||
} | ||
@Parcelize data class Available(val expiryDateTime: DateTime) : AccountExpiry() | ||
|
||
@Parcelize data object Missing : AccountExpiry() | ||
|
||
fun date(): DateTime? { | ||
return (this as? Available)?.expiryDateTime | ||
} | ||
|
||
open fun daysLeft(): Int? { | ||
return (this as? Available)?.daysLeft() | ||
} | ||
} |