Any idea yet how a multiplatform date+time library...
# multiplatform
m
Any idea yet how a multiplatform date+time library could look like? Like
java.time
? Or like Swift's? Or a mix of both? Java's seems to be focused on the Gregorian calendar while Swift's is more generic.
m
I have never used swift, so this maybe off question, but is there any practical reason to use any other calendar instead of gregorian? It does not look like gregorian is going away any time soon.
c
In some parts of the world other calendars are in active use: https://en.wikipedia.org/wiki/Civil_calendar
Another example is the Chinese Lunar Calendar. It's not used for official dates, but used for orientation about holidays and even birthdays, sometimes.
d
m
Yeah I've seen that one. I don't like it's API though. It doesn't seem to have LocalDate/LocalDateTime/LocalTime alternatives, it doesn't have time zones, it adds unrelated functionality (measurement/performance), it pollutes standard types with extension properties (e.g. Int.minute), etc.
t
You can ask @Deactivated User for new features/APIs
k
There has been discussion of a date/time lib from JB, and others have discussed porting 310. I tend to agree with concerns about klock. At a more general level, Date/time is tough, and the stability is critical. Building one from scratch requires a pretty heavy burden of proof about correctness (plus time zones, etc). Edge cases are seemingly endless so evaluating one is non-trivial (IMHO).
👍 3
Having said that, Java’s SimpleDateFormat not being thread safe is bananas, and has produced one of my favorite production war stories, so even the standard libraries can be rough, but anyway…
m
Yeah, that thread safety issue caused me headaches too. Luckily
java.time.format.DateTimeFormatter
is finally thread-safe 🙂
e
We are prototyping durations support for common stdlib (for measuring date/time intervals and for use with various delay/timeout functions in a type-safe way) for a future release, but we don’t currently plan to have full blown date-time (with time-zones, etc) for stdlib (too heavy). That will have to be a separate mpp library at the end.
🙏 3
🤩 2
m
Even Java has it's problems 😂
Copy code
println(Clock.tick(Clock.systemUTC(), Duration.ofNanos(2)).millis())
Copy code
Exception in thread "main" java.lang.ArithmeticException: / by zero
	at java.base/java.lang.Math.floorDiv(Math.java:1224)
	at java.base/java.lang.Math.floorMod(Math.java:1330)
	at java.base/java.time.Clock$TickClock.millis(Clock.java:711)
😨 1