npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@item-enonic-types/lib-time

v1.0.4

Published

Type definitions for lib-time

Downloads

311

Readme

Time library for Enonic XP

This library enables the usage of classes from the java.time package from Enonic XP application code. Other JavaScript-based time libraries like Moment.js or date-fns will negatively impact your bundle size and build time. This library is only a thin TypeScript-wrapper around the excellent core java.time library already present in your system!

Installation

To install this library you need to add a new dependency to your app's build.gradle file.

Gradle

repositories {
  maven { url 'https://jitpack.io' }
}

dependencies {
  include "no.item:lib-xp-time:1.0.3"
}

TypeScript

To update the version of enonic-types in package.json using npm, run the following command:

npm install --save-dev @item-enonic-types/lib-time

You can add the following changes to your tsconfig.json to get TypeScript-support.

{
  "compilerOptions": {
+   "baseUrl": "./",
+   "paths": {
+     "/lib/xp/*": ["./node_modules/@enonic-types/lib-*"],
+     "/lib/*": [ "./node_modules/@item-enonic-types/lib-*" ,"./src/main/resources/lib/*"],
+   }
  }
}

Usage

You can import java.time and java.time.format classes from "/lib/time".

Example of date math on a LocalDateTime using "/lib/time":

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"

Example of doing time math using a ZonedDateTime:

import { ZonedDateTime } from "/lib/time";

const date = ZonedDateTime.parse("2023-02-21T12:15:30+01:00");
const fiftyMinutesAgo = date.minusMinutes(50);
const time = fiftyMinutesAgo.toLocalTime();
// time = "11:25:30"

This library also exposes a utility function formatDate() to simply format a date:

import { formatDate } from "/lib/time";

const today = formatDate({
  date: "2023-02-21",
  pattern: "dd-MM-yyyy",
  locale: "no"
});
// today = "21-02-2023"

Use formatDate() with a given timezoneId

import { formatDate } from "/lib/time";

const today = formatDate({
  date: "2023-02-21",
  pattern: "dd-MM-yyyy",
  locale: "no",
  timezoneId: "Europe/Oslo"
});
// today = "21-02-2023"

Example of using Locale in formatting a LocalDateTime and get a normalized timestamp :

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

const today = LocalDateTime.parse("2023-02-21T12:15:30");
const formatter = DateTimeFormatter.ofPattern("EEEE d. MMMM yyyy hh:mm:ss", new Locale("no"));
const time = today.format(formatter);
// time = "tirsdag 21. februar 2023 12:15:30"

Constants exposed from "/lib/time"

The following classes is exposed/exported from "/lib/time":

  • DateTimeFormatter
  • DayOfWeek
  • Instant
  • LocalDate
  • LocalDateTime
  • Locale
  • LocalTime
  • Month
  • OffsetDateTime
  • OffsetTime
  • ZonedDateTime
  • ZoneId
  • ZoneOffset

Building

To build the project run the following code

./gradlew build

Deploy locally

Deploy locally for testing purposes:

./gradlew publishToMavenLocal

Deploy to Jitpack

Go to the Jitpack page for lib-xp-time to deploy from GitHub (after creating a new versioned release).