Skip to content

Commit

Permalink
Merge pull request #13393 from woocommerce/issue/13390-fix-dateformat…
Browse files Browse the repository at this point in the history
…-crash

Attempt to fix a crash that could occur when formatting dates and times
  • Loading branch information
irfano authored Jan 28, 2025
2 parents 73135c1 + c98ba62 commit efb750f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*** For entries which are touching the Android Wear app's, start entry with `[WEAR]` too.
21.6
-----

- [Internal] [*] Fixed a bug that could lead to a crash when formatting dates and times [https://github.com/woocommerce/woocommerce-android/pull/13393]

21.5
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,30 @@ class DateUtils @Inject constructor(
private val crashLogger: CrashLogging,
private val selectedSite: SelectedSite
) {
private val friendlyMonthDayFormat: SimpleDateFormat = SimpleDateFormat("MMM d", locale)
private val friendlyMonthDayYearFormat: SimpleDateFormat = SimpleDateFormat("MMM d, yyyy", locale)
private val friendlyTimeFormat: SimpleDateFormat = SimpleDateFormat("h:mm a", locale)
private val friendlyLongMonthDayFormat: SimpleDateFormat = SimpleDateFormat("MMMM dd", locale)

private val weekOfYearStartingMondayFormat: SimpleDateFormat = SimpleDateFormat("yyyy-ww", locale).apply {
calendar = Calendar.getInstance().apply {
// Ensure the date formatter follows ISO8601 week standards:
// the first day of a week is a Monday, and the first week of the year starts on the first Monday
// (and not on the Monday of the week containing January 1st, which may be in the previous year)
firstDayOfWeek = Calendar.MONDAY
minimalDaysInFirstWeek = 7
private val friendlyMonthDayFormat: SimpleDateFormat
get() = SimpleDateFormat("MMM d", locale)
private val friendlyMonthDayYearFormat: SimpleDateFormat
get() = SimpleDateFormat("MMM d, yyyy", locale)
private val friendlyTimeFormat: SimpleDateFormat
get() = SimpleDateFormat("h:mm a", locale)
private val friendlyLongMonthDayFormat: SimpleDateFormat
get() = SimpleDateFormat("MMMM dd", locale)

private val weekOfYearStartingMondayFormat: SimpleDateFormat
get() = SimpleDateFormat("yyyy-ww", locale).apply {
calendar = Calendar.getInstance().apply {
// Ensure the date formatter follows ISO8601 week standards:
// the first day of a week is a Monday, and the first week of the year starts on the first Monday
// (and not on the Monday of the week containing January 1st, which may be in the previous year)
firstDayOfWeek = Calendar.MONDAY
minimalDaysInFirstWeek = 7
}
}
}

private val shortMonths = DateFormatSymbols(locale).shortMonths

private val yyyyMMddFormat = SimpleDateFormat("yyyy-MM-dd", Locale.US)
private val yyyyMMddFormat
get() = SimpleDateFormat("yyyy-MM-dd", Locale.US)

/**
* Given an ISO8601 date of volatile format,
Expand Down

0 comments on commit efb750f

Please sign in to comment.