New Library Time

We have a cool new addition to our market from Item Consulting
Time library

While other time libraries include a whole new way of dealing with time, why not just use the built in backend for dealing with it. The libraries used the java time to handle all dates, and exposes it to JS.

I am going to try this out and use it for projects I work on!

Thank you Marcus Scheie from Item Consulting for adding this to our Market

3 Likes

Hi guys,

I think this library is a must-have for every XP7-project!

The reason Item created this library is that JavaScript-based date libraries (like MomentJs or DateFns) adds a lot to your build time, your bundle size and your memory usage.

We had the realization that XP actually already has a really good Date-library built in. The java.time package!

What the Time Library does is just expose that built in library to the developer and provide TypeScript-types.


Here is a usage example:

import { LocalDateTime, DateTimeFormatter } from "/lib/time";

const today = LocalDateTime.parse("2023-02-21T12:15:30");
const formatter = DateTimeFormatter.ofPattern("dd.MM hh:mm")
const inThreeWeeksStr = today
  .plusWeeks(3)
  .format(formatter);
// inThreeWeeksStr = "14.03 12:15"

There is also a suite of unit tests that shows that java.time works in a XP context.

– Tom Arild

2 Likes