Skip to content

OBS-1831 Fix unparseable date: "01/01/2025 " exception during stock movements#5068

Merged
ewaterman merged 1 commit intodevelopfrom
bug/OBS-1831-unparseable-date
Mar 4, 2025
Merged

OBS-1831 Fix unparseable date: "01/01/2025 " exception during stock movements#5068
ewaterman merged 1 commit intodevelopfrom
bug/OBS-1831-unparseable-date

Conversation

@ewaterman
Copy link
Member

@ewaterman ewaterman commented Feb 26, 2025

✨ Description of Change

Link to GitHub issue or Jira ticket:

Description: This change switches the parsing of dateShipped and dateRequested fields during stock movements to use the new DateUtil.asDate method (with no SimpleDateFormat provided so that it uses the flexible format).

I also modified how the method works so that it uses the same DateTimeFormatter that we use when parsing a String to an Instant. That way it gets around the issue with parsing "MM/dd/yyyy" and defaulting to the local timezone (now it always uses UTC).


📷 Screenshots & Recordings (optional)

image-20241120-211537

@ewaterman ewaterman requested a review from jmiranda February 26, 2025 00:11
@ewaterman ewaterman self-assigned this Feb 26, 2025
@github-actions github-actions bot added type: bug Addresses unintended behaviours of the app domain: backend Changes or discussions relating to the backend server flag: config change Hilights a pull request that contains a change to the app config labels Feb 26, 2025
}

private Date parseDateShipped(String date) {
return DateUtil.asDate(date, Constants.DELIVERY_DATE_FORMATTER)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the real change. Notice that before we were providing the specific formatter to use but now we don't. Now this will use the flexible date formatter which allows for a much wider range of possible inputs

/**
* DateTimeFormatter used to parse a String to a datetime class, such as java.time.Instant.
*/
static final DateTimeFormatter FLEXIBLE_DATE_TIME_ZONE_FORMAT = new DateTimeFormatterBuilder()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not new code. Just moved from InstantValueConverter so that it can be shared

"01/01/00 00:00 Z" || "0001-01-01T00:00:00Z" | "No time or timezone our format two digit year"
// When not given a time or timezone, we default to midnight UTC.
"01/01/2000" || "2000-01-01T00:00:00Z" | "No time or timezone our format"
"2000-01-01" || "2000-01-01T00:00:00Z" | "No time or timezone ISO format"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can parse to a Date without providing a timezone and it automatically uses UTC now. Yay!

@codecov
Copy link

codecov bot commented Feb 26, 2025

Codecov Report

Attention: Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 7.97%. Comparing base (f3d5de6) to head (f8d28fa).
Report is 213 commits behind head on develop.

Files with missing lines Patch % Lines
...ih/warehouse/api/StockMovementApiController.groovy 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             develop   #5068   +/-   ##
=========================================
  Coverage       7.97%   7.97%           
- Complexity       907     912    +5     
=========================================
  Files            632     632           
  Lines          42983   42960   -23     
  Branches       10406   10404    -2     
=========================================
  Hits            3427    3427           
+ Misses         39035   39011   -24     
- Partials         521     522    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

# ahead of UTC, this can cause the date to actually become the next day. It can also cause
# inconsistencies across hosts/environments if they're configured for different local timezones.
# Avoid using this format going forward! Only kept to maintain backwards compatability.
- 'MM/dd/yyyy'
Copy link
Member Author

@ewaterman ewaterman Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this problem will always be present so long as we use the Date class. Explicility calling

Date date = DateUtil.asDate("01/01/2000") 

will correctly default to UTC, but if we rely on Grails' databinding (ie have a controller method take in a Command object arg that has a Date field), Strings like "01/01/2000" will default to the local server time. This is why switching to Instant and LocalDate for new features is better

@ewaterman ewaterman changed the title Fix unparseable date: "01/01/2025 " exception during stock movements OBS-1831 Fix unparseable date: "01/01/2025 " exception during stock movements Feb 27, 2025
@ewaterman ewaterman merged commit ca2ae37 into develop Mar 4, 2025
9 checks passed
@ewaterman ewaterman deleted the bug/OBS-1831-unparseable-date branch March 4, 2025 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: backend Changes or discussions relating to the backend server flag: config change Hilights a pull request that contains a change to the app config type: bug Addresses unintended behaviours of the app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants