Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix a crash that could occur when formatting dates and times #13393

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading