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

refactor: Typed timestamp utility #33512

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

zharinov
Copy link
Collaborator

@zharinov zharinov commented Jan 10, 2025

Changes

Context

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@zharinov zharinov requested a review from rarkins January 10, 2025 14:37
@zharinov zharinov marked this pull request as draft January 10, 2025 14:58
@zharinov zharinov marked this pull request as ready for review January 10, 2025 16:12
@zharinov zharinov requested a review from viceice January 10, 2025 17:08
@rarkins rarkins changed the title feat: Typed timestamp utility refactor: Typed timestamp utility Jan 10, 2025

export function asTimestamp(input: unknown): Timestamp | null {
if (input instanceof Date) {
const date = DateTime.fromJSDate(input, { zone: 'UTC' });
Copy link
Member

Choose a reason for hiding this comment

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

don't we change the timezone to a probably wrong value here? or is datetime correctly converting it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's converted from whatever timezone the original value is, to the UTC

return millisDate.toISO() as Timestamp;
}

const secondsDate = DateTime.fromSeconds(input, { zone: 'UTC' });
Copy link
Member

Choose a reason for hiding this comment

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

do we need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If some datasource is capable of providing timestamp in the millisecond format, I could imagine it's done in the seconds format as well

lib/util/timestamp.ts Show resolved Hide resolved
@zharinov zharinov requested a review from viceice January 10, 2025 19:07
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.

2 participants