fix: use UTC dates for daily question keys across all date consumers

This commit is contained in:
null 2026-06-18 03:11:22 -05:00
parent fb0e8fbaab
commit 8b394ab40f
4 changed files with 14 additions and 16 deletions

View File

@ -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,

View File

@ -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)
}
}
}

View File

@ -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) } }

View File

@ -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()