From 8b394ab40f37e301daa25448937f2d0386bd5d6c Mon Sep 17 00:00:00 2001 From: null Date: Thu, 18 Jun 2026 03:11:22 -0500 Subject: [PATCH] fix: use UTC dates for daily question keys across all date consumers --- .../core/notifications/TokenRegistrar.kt | 4 +--- .../data/remote/FirestoreAnswerDataSource.kt | 20 +++++++++---------- .../ui/answers/AnswerRevealViewModel.kt | 4 ++-- .../ui/questions/DailyQuestionViewModel.kt | 2 +- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/app/closer/core/notifications/TokenRegistrar.kt b/app/src/main/java/app/closer/core/notifications/TokenRegistrar.kt index f53fbdf9..732e9ec3 100644 --- a/app/src/main/java/app/closer/core/notifications/TokenRegistrar.kt +++ b/app/src/main/java/app/closer/core/notifications/TokenRegistrar.kt @@ -37,9 +37,7 @@ class TokenRegistrar @Inject constructor( userRepository.storeFcmToken(uid, token) userRepository.storeTokenMetadata(uid, token, metadata) - - Result.success(Unit) - }.getOrElse { Result.failure(it) } + } data class DeviceMetadata( val platform: String, diff --git a/app/src/main/java/app/closer/data/remote/FirestoreAnswerDataSource.kt b/app/src/main/java/app/closer/data/remote/FirestoreAnswerDataSource.kt index 16cff918..48cf1c0f 100644 --- a/app/src/main/java/app/closer/data/remote/FirestoreAnswerDataSource.kt +++ b/app/src/main/java/app/closer/data/remote/FirestoreAnswerDataSource.kt @@ -42,7 +42,7 @@ class FirestoreAnswerDataSource @Inject constructor(private val db: FirebaseFire userId: String, answer: LocalAnswer ): Unit = suspendCancellableCoroutine { cont -> - val date = todayCstString() + val date = todayUtcString() val data = mapOf( "userId" to userId, "questionId" to questionId, @@ -62,12 +62,12 @@ class FirestoreAnswerDataSource @Inject constructor(private val db: FirebaseFire } /** - * Fetches a partner's answer for the current CST date. + * Fetches a partner's answer for the current UTC date. */ suspend fun getAnswerForUser( coupleId: String, userId: String, - date: String = todayCstString() + date: String = todayUtcString() ): LocalAnswer? = suspendCancellableCoroutine { cont -> answerRef(coupleId, date, userId) .get() @@ -84,7 +84,7 @@ class FirestoreAnswerDataSource @Inject constructor(private val db: FirebaseFire /** * Reads the couple-scoped daily question assignment for today. */ - suspend fun getDailyQuestionAssignment(coupleId: String, date: String = todayCstString()): DailyQuestionAssignment? = + suspend fun getDailyQuestionAssignment(coupleId: String, date: String = todayUtcString()): DailyQuestionAssignment? = suspendCancellableCoroutine { cont -> dailyQuestionRef(coupleId, date) .get() @@ -109,7 +109,7 @@ class FirestoreAnswerDataSource @Inject constructor(private val db: FirebaseFire * Calls the cloud function to assign a daily question for the couple immediately. * Used when a couple is newly created and has no assignment yet. */ - suspend fun requestDailyQuestionAssignment(coupleId: String, date: String = todayCstString()): Unit = + suspend fun requestDailyQuestionAssignment(coupleId: String, date: String = todayUtcString()): Unit = suspendCancellableCoroutine { cont -> val functions = com.google.firebase.functions.FirebaseFunctions.getInstance() functions @@ -145,12 +145,12 @@ class FirestoreAnswerDataSource @Inject constructor(private val db: FirebaseFire ) companion object { - private const val CST_ID = "America/Chicago" - - fun todayCstString(): String { + // UTC keeps both partners on the same date key regardless of where they are. + // The Cloud Functions assignDailyQuestion must also use UTC when creating date docs. + fun todayUtcString(): String { val fmt = SimpleDateFormat("yyyy-MM-dd", Locale.US) - fmt.timeZone = TimeZone.getTimeZone(CST_ID) - return fmt.format(Calendar.getInstance(TimeZone.getTimeZone(CST_ID)).time) + fmt.timeZone = TimeZone.getTimeZone("UTC") + return fmt.format(Calendar.getInstance(TimeZone.getTimeZone("UTC")).time) } } } diff --git a/app/src/main/java/app/closer/ui/answers/AnswerRevealViewModel.kt b/app/src/main/java/app/closer/ui/answers/AnswerRevealViewModel.kt index 96045574..58583a32 100644 --- a/app/src/main/java/app/closer/ui/answers/AnswerRevealViewModel.kt +++ b/app/src/main/java/app/closer/ui/answers/AnswerRevealViewModel.kt @@ -62,7 +62,7 @@ class AnswerRevealViewModel @Inject constructor( firestoreAnswerDataSource.getAnswerForUser( coupleId = coupleId, userId = partnerId, - date = FirestoreAnswerDataSource.todayCstString() + date = FirestoreAnswerDataSource.todayUtcString() ) }.onFailure { crashReporter.recordException(it) }.getOrNull() } else null @@ -115,7 +115,7 @@ class AnswerRevealViewModel @Inject constructor( firestoreAnswerDataSource.getAnswerForUser( coupleId = coupleId, userId = partnerId, - date = FirestoreAnswerDataSource.todayCstString() + date = FirestoreAnswerDataSource.todayUtcString() ) }.onFailure { crashReporter.recordException(it) }.getOrNull() partnerAnswer?.let { _uiState.update { it.copy(partnerAnswer = partnerAnswer) } } diff --git a/app/src/main/java/app/closer/ui/questions/DailyQuestionViewModel.kt b/app/src/main/java/app/closer/ui/questions/DailyQuestionViewModel.kt index c55ef486..bbbf7474 100644 --- a/app/src/main/java/app/closer/ui/questions/DailyQuestionViewModel.kt +++ b/app/src/main/java/app/closer/ui/questions/DailyQuestionViewModel.kt @@ -91,7 +91,7 @@ class DailyQuestionViewModel @Inject constructor( } val coupleId = couple.id - val today = FirestoreAnswerDataSource.todayCstString() + val today = FirestoreAnswerDataSource.todayUtcString() val assignment = runCatching { firestoreAnswerDataSource.getDailyQuestionAssignment(coupleId, today) }.onFailure { crashReporter.recordException(it) }.getOrNull()