Skip to content

Commit

Permalink
Merge pull request #112 from paug/fix-timezone-of-timestamps
Browse files Browse the repository at this point in the history
Use Paris timezone for dates
  • Loading branch information
martinbonnin authored Apr 22, 2022
2 parents 945c449 + 47fbbf1 commit 5910eb9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private fun getFormattedDateAndRoom(room: Room, startTimestamp: Long, endTimesta
startTimestamp,
endTimestamp,
DateUtils.FORMAT_SHOW_WEEKDAY or DateUtils.FORMAT_SHOW_TIME or DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_SHOW_YEAR,
null).toString()
"Europe/Paris").toString()
return if (room.name.isNotEmpty()) {
stringResource(R.string.sessionDateWithRoomPlaceholder, sessionDate, room.name)
} else {
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/fr/paug/androidmakers/util/TimeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.material.contentColorFor
import fr.paug.androidmakers.R
import java.time.Duration
import java.time.OffsetDateTime
import java.time.ZoneId
import java.util.*

object TimeUtils {
Expand All @@ -16,12 +17,18 @@ object TimeUtils {
fun parseIso8601(iso8601: String): Date {
return Date(OffsetDateTime.parse(iso8601).toEpochSecond() * 1000)
}

/**
* format the time as HH:mm in the timezone of the event
*/
fun formatShortTime(context: Context?, time: Date?): String {

// Android DateFormatter will honor the user's current settings.
val dateFormat = DateFormat.getTimeFormat(context)
// Override with Timezone based on settings since users can override their phone's timezone
// with Pacific time zones.
val tz = TimeZone.getDefault()

// Display the time in the local time as everyone will be on site so it makes
// planning in advance easier
val tz = TimeZone.getTimeZone(ZoneId.of("Europe/Paris"))
if (tz != null) {
dateFormat.timeZone = tz
}
Expand Down

0 comments on commit 5910eb9

Please sign in to comment.