Skip to content

Commit 913fd01

Browse files
committed
Parse domain expiry as a date-only string after the wordpress-rs 0.6.0 bump
`AllDomainItem.expiry` changed from `Option<WpGmtDateTime>` (`java.util.Date` in Kotlin) to `Option<WpDateString>` (`String`), because `/all-domains/` returns expiry as a date-only `"YYYY-MM-DD"` value rather than a full datetime. Parse it with `LocalDate.parse` instead of converting a `Date` through the system time zone, and drop the now-unused `asLegacyDate` preview helper. `WpDateString` carries the raw API string with no format validation, so the parse is wrapped in `runCatching` and falls back to no expiry.
1 parent a1d1201 commit 913fd01

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

WordPress/src/main/java/org/wordpress/android/ui/domains/management/DomainManagementViewModel.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import uniffi.wp_api.AllDomainItem
2929
import uniffi.wp_api.DomainListItemStatus
3030
import uniffi.wp_api.DomainListItemStatusType
3131
import java.time.LocalDate
32-
import java.time.ZoneId
33-
import java.util.Date
3432
import javax.inject.Inject
3533
import javax.inject.Named
3634

@@ -168,7 +166,7 @@ sealed class DomainCardUiState {
168166
statusText = domain.domainStatus.statusText,
169167
textColor = domain.domainStatus.textColor,
170168
isBold = domain.domainStatus.isBold,
171-
expiry = domain.expiry?.toLocalDate(),
169+
expiry = domain.expiry?.toLocalDateOrNull(),
172170
)
173171
)
174172
}
@@ -185,8 +183,9 @@ sealed class StatusRowUiState {
185183
) : StatusRowUiState()
186184
}
187185

188-
private fun Date.toLocalDate(zoneId: ZoneId = ZoneId.systemDefault()) =
189-
toInstant().atZone(zoneId).toLocalDate()
186+
// `AllDomainItem.expiry` is an unvalidated API string in "YYYY-MM-DD" form.
187+
private fun String.toLocalDateOrNull() =
188+
runCatching { LocalDate.parse(this) }.getOrNull()
190189

191190
val DomainListItemStatus.indicatorColor
192191
@Composable

WordPress/src/main/java/org/wordpress/android/ui/domains/management/DomainsListCard.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ import uniffi.wp_api.DomainListItemStatusId
3131
import uniffi.wp_api.DomainListItemStatusType
3232
import uniffi.wp_api.DomainSubtype
3333
import uniffi.wp_api.DomainSubtypeId
34-
import java.time.LocalDate
35-
import java.time.ZoneId
36-
import java.util.Date
3734

3835
@OptIn(ExperimentalMaterial3Api::class)
3936
@Composable
@@ -120,7 +117,7 @@ fun DomainListCard(
120117
)
121118
@Composable
122119
fun DomainListCardPreview() {
123-
val expiry = LocalDate.of(2024, 8, 15).asLegacyDate()
120+
val expiry = "2024-08-15"
124121

125122
AppThemeM3 {
126123
Column(
@@ -156,7 +153,7 @@ private fun previewDomain(
156153
blogName: String = "A cool website",
157154
status: DomainListItemStatusType = DomainListItemStatusType.Success,
158155
statusLabel: String = "Active",
159-
expiry: Date? = null,
156+
expiry: String? = null,
160157
) = AllDomainItem(
161158
domain = domain,
162159
subtype = DomainSubtype(
@@ -182,7 +179,3 @@ private fun previewDomain(
182179
subscriptionId = null,
183180
tags = emptyList(),
184181
)
185-
186-
private fun LocalDate.asLegacyDate(
187-
zoneId: ZoneId = ZoneId.systemDefault()
188-
) = Date.from(atStartOfDay(zoneId).toInstant())

0 commit comments

Comments
 (0)