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

Proposal for JS for implementing .now() without tzdb for all "time" classes except for ZonedDateTime #480

Open
gatisnolv opened this issue Oct 30, 2023 · 2 comments

Comments

@gatisnolv
Copy link

With these helpers on JS (browsers, node.js), we obtain an OffsetDateTime.now() equivalent (of course up to millisecond resolution due to JS nature) without the need to add tzdb. This unlocks all of {LocalDate, LocalDateTime, LocalTime, MonthDay, OffsetDateTime, OffsetTime, Year, YearMonth}.now() straightforward implementations in terms of the OffsetDateTime.now() instance. And only ZonedDateTime, which intuitively should be the only one that requires actual tz data is left with that need.

def utcOffsetSeconds(ms: Long) = -new Date(ms.toDouble).getTimezoneOffset().toInt * 60

def offsetDateTimeInDefaultTimeZone(instant: Instant) = instant.atOffset(ZoneOffset.ofTotalSeconds(utcOffsetSeconds(instant.toEpochMilli)))

def offsetDateTimeInDefaultTimeZoneNow() = offsetDateTimeInDefaultTimeZone(Instant.now())

What do you think about this?

@gatisnolv gatisnolv changed the title Proposal for JS for implementing .now() without tzdb for all classes except for ZonedDateTime Proposal for JS for implementing .now() without tzdb for all "time" classes except for ZonedDateTime Nov 10, 2023
@gatisnolv
Copy link
Author

@cquiroz Care to comment?

@cquiroz
Copy link
Owner

cquiroz commented Nov 29, 2023

Hi

Sorry I've been quite busy lately, this sounds intriguing

Have you thought how would it affect scala-native?

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

No branches or pull requests

2 participants