Skip to content

DT-4133 Migrate from momentjs to luxon #5403

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

Merged
merged 7 commits into from
Jun 16, 2025
Merged

DT-4133 Migrate from momentjs to luxon #5403

merged 7 commits into from
Jun 16, 2025

Conversation

hjvuor
Copy link
Contributor

@hjvuor hjvuor commented Jun 3, 2025

Proposed Changes

  • More changes replacing use of moment with luxon
  • This PR includes changes that are relatively straightforward, rest of the changes will be included on a later PR to avoid merge conflicts
  • In most cases we retain the original logic
    • It's questionable if we want to keep it or simplify with luxon specific operations

Pull Request Check List

  • A reasonable set of unit tests is included
  • Console does not show new warnings/errors
  • Changes are documented or they are self explanatory
  • This pull request does not have any merge conflicts
  • All existing tests pass in CI build

Review

  • Read and verify the code changes
  • Test the functionality by running the UI locally with all popular browsers available in your platform
  • Check that the implementation matches the design, when such one is defined in a Jira issue
  • Merge the pull request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this component we are creating DateTime objects and mostly formatting them as strings for comparisons. It's debatable if it would be more robust to compare the objects directly.

@hjvuor hjvuor requested a review from tkalvas June 3, 2025 14:02
@vesameskanen
Copy link
Member

looks good to me. Anyway, maybe we should wait until the next UI release (next wednesday) before merging this many changes. Summer break gives us plenty of time to test the changes in dev.

@@ -80,8 +80,12 @@ function ParkAndRideContent(
if (to - from - 60 * 60 * 24 === 0) {
return [`24${intl.formatMessage({ id: 'hour-short' })}`];
}
const formattedFrom = moment.utc(from * 1000).format('HH:mm');
const formattedTo = moment.utc(to * 1000).format('HH:mm');
const formattedFrom = DateTime.fromMillis(from * 1000)
Copy link
Contributor

Choose a reason for hiding this comment

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

DateTime.fromSecond

const formattedFrom = DateTime.fromMillis(from * 1000)
.toUTC()
.toFormat('HH:mm');
const formattedTo = DateTime.fromMillis(to * 1000)
Copy link
Contributor

Choose a reason for hiding this comment

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

fromSeconds

const from = moment.utc(timeSpans.from * 1000).format('HH:mm');
const to = moment.utc(timeSpans.to * 1000).format('HH:mm');
const day = date.toLocaleString(currentLanguage, { weekday: 'short' });
const from = DateTime.fromMillis(timeSpans.from * 1000)
Copy link
Contributor

Choose a reason for hiding this comment

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

fromSeconds

const from = DateTime.fromMillis(timeSpans.from * 1000)
.toUTC()
.toFormat('HH:mm');
const to = DateTime.fromMillis(timeSpans.to * 1000)
Copy link
Contributor

Choose a reason for hiding this comment

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

fromSeconds

app/constants.js Outdated
@@ -66,6 +66,7 @@ export const RealtimeStateType = Object.freeze({
* This is the date format string to use for querying dates from OTP.
*/
export const DATE_FORMAT = 'YYYYMMDD';
export const DATE_FORMAT_LUXON = 'yyyyLLdd';
Copy link
Contributor

Choose a reason for hiding this comment

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

The bare string 'yyyyLLdd' appears in several places, but they could all use the named constant.

@@ -97,7 +97,7 @@ export function parseMessage(topic, message, defaultFeedId) {
operatingDay:
parsedMessage.oday && parsedMessage.oday !== 'XXX'
? parsedMessage.oday
: moment().format('YYYY-MM-DD'),
: DateTime.now().toFormat('yyyy-LL-dd'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually ALL the date formatting constants could be named and collected in a single place.

@hjvuor hjvuor requested a review from tkalvas June 16, 2025 11:24
@tkalvas tkalvas merged commit a49be0f into v3 Jun 16, 2025
6 checks passed
@tkalvas tkalvas deleted the DT-4133-replace-moment branch June 16, 2025 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants