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.storeFcmToken(uid, token)
userRepository.storeTokenMetadata(uid, token, metadata) userRepository.storeTokenMetadata(uid, token, metadata)
}
Result.success(Unit)
}.getOrElse { Result.failure(it) }
data class DeviceMetadata( data class DeviceMetadata(
val platform: String, val platform: String,

View File

@ -42,7 +42,7 @@ class FirestoreAnswerDataSource @Inject constructor(private val db: FirebaseFire
userId: String, userId: String,
answer: LocalAnswer answer: LocalAnswer
): Unit = suspendCancellableCoroutine { cont -> ): Unit = suspendCancellableCoroutine { cont ->
val date = todayCstString() val date = todayUtcString()
val data = mapOf( val data = mapOf(
"userId" to userId, "userId" to userId,
"questionId" to questionId, "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( suspend fun getAnswerForUser(
coupleId: String, coupleId: String,
userId: String, userId: String,
date: String = todayCstString() date: String = todayUtcString()
): LocalAnswer? = suspendCancellableCoroutine { cont -> ): LocalAnswer? = suspendCancellableCoroutine { cont ->
answerRef(coupleId, date, userId) answerRef(coupleId, date, userId)
.get() .get()
@ -84,7 +84,7 @@ class FirestoreAnswerDataSource @Inject constructor(private val db: FirebaseFire
/** /**
* Reads the couple-scoped daily question assignment for today. * 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 -> suspendCancellableCoroutine { cont ->
dailyQuestionRef(coupleId, date) dailyQuestionRef(coupleId, date)
.get() .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. * 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. * 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 -> suspendCancellableCoroutine { cont ->
val functions = com.google.firebase.functions.FirebaseFunctions.getInstance() val functions = com.google.firebase.functions.FirebaseFunctions.getInstance()
functions functions
@ -145,12 +145,12 @@ class FirestoreAnswerDataSource @Inject constructor(private val db: FirebaseFire
) )
companion object { companion object {
private const val CST_ID = "America/Chicago" // 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 todayCstString(): String { fun todayUtcString(): String {
val fmt = SimpleDateFormat("yyyy-MM-dd", Locale.US) val fmt = SimpleDateFormat("yyyy-MM-dd", Locale.US)
fmt.timeZone = TimeZone.getTimeZone(CST_ID) fmt.timeZone = TimeZone.getTimeZone("UTC")
return fmt.format(Calendar.getInstance(TimeZone.getTimeZone(CST_ID)).time) return fmt.format(Calendar.getInstance(TimeZone.getTimeZone("UTC")).time)
} }
} }
} }

View File

@ -62,7 +62,7 @@ class AnswerRevealViewModel @Inject constructor(
firestoreAnswerDataSource.getAnswerForUser( firestoreAnswerDataSource.getAnswerForUser(
coupleId = coupleId, coupleId = coupleId,
userId = partnerId, userId = partnerId,
date = FirestoreAnswerDataSource.todayCstString() date = FirestoreAnswerDataSource.todayUtcString()
) )
}.onFailure { crashReporter.recordException(it) }.getOrNull() }.onFailure { crashReporter.recordException(it) }.getOrNull()
} else null } else null
@ -115,7 +115,7 @@ class AnswerRevealViewModel @Inject constructor(
firestoreAnswerDataSource.getAnswerForUser( firestoreAnswerDataSource.getAnswerForUser(
coupleId = coupleId, coupleId = coupleId,
userId = partnerId, userId = partnerId,
date = FirestoreAnswerDataSource.todayCstString() date = FirestoreAnswerDataSource.todayUtcString()
) )
}.onFailure { crashReporter.recordException(it) }.getOrNull() }.onFailure { crashReporter.recordException(it) }.getOrNull()
partnerAnswer?.let { _uiState.update { it.copy(partnerAnswer = partnerAnswer) } } partnerAnswer?.let { _uiState.update { it.copy(partnerAnswer = partnerAnswer) } }

View File

@ -91,7 +91,7 @@ class DailyQuestionViewModel @Inject constructor(
} }
val coupleId = couple.id val coupleId = couple.id
val today = FirestoreAnswerDataSource.todayCstString() val today = FirestoreAnswerDataSource.todayUtcString()
val assignment = runCatching { val assignment = runCatching {
firestoreAnswerDataSource.getDailyQuestionAssignment(coupleId, today) firestoreAnswerDataSource.getDailyQuestionAssignment(coupleId, today)
}.onFailure { crashReporter.recordException(it) }.getOrNull() }.onFailure { crashReporter.recordException(it) }.getOrNull()