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

globol

v0.11.3

Published

Javascript/Typescript date/time as it should be: immutable, fluent, multi-zone, intuitive. Inspired by the masterful java.time library which suddenly made dates easy.

Downloads

128

Readme

  • Dates, times, timestamps, time zones, durations, weekdays.
  • Conversion between them and arithmetics with them.
  • Type safe. You want to express an moment in time, a date on a calendar, a time on the clock? In a specific time zone, or you don't care? No longer will nuances like these overwhelm or confuse. It turns out time is very easy: you just needed the right API.
  • Immutable.
  • Fail early. No wrong input, like NaNs for milliseconds, sneaking into your date objects. Globol checks its input, and throws errors with helpful messages if there's something wrong.
  • Fluent. No searching the web for which functions suit your needs, but finding what you need with auto-complete.
  • In-place documentation. Help yourself without leaving your IDE, with extensive JSDoc on all methods and functions.
  • ISO-8601-compliant serilization/deserialization of all data representations.
  • Under the hood, currently uses the well-tested, well-trusted moment.js internally for parsing, formatting and time zone conversions.
  • Uses moment-timezone for time zone information. Future work is to make this optionally injectable, so globol can be smaller for users that need it to be.

Example:

const timeInNewYork = now()     // returns an Instant in time (≡ a timestamp)
    .atZone('America/New_York') // returns that Instant expressed in a certain time zone; a ZonedDateTime
    .toLocalTime();             // returns a time on the clock without a date, a LocalTime

Install

npm install globol

How to use

Get the current timestamp

import {Instant} from 'globol';

Instant.now()                // returns an Instant

All types and functions are in the globol module, so we'll leave the import statement out from now. You can also use a shorthand for the current time:

now()                        // returns an Instant

Get "tomorrow, in this timezone"

const tomorrow = now()          // returns an Instant
    .atZone(TimeZone.browser()) // returns a ZonedDateTime
    .toLocalDate()              // returns a LocalDate (dropped the zone and the time)
    .plus({days: 1});

Get the current time on the clock (e.g. '14:57') in Berlin

now()                        // a timestamp
    .atZone('Europe/Berlin') // returns a ZonedDateTime: the timestamp represented in this zone
    .toLocalTime()           // returns a LocalTime, e.g. '14:57'

This library consists mainly of a few smart data types that each describe a different concept of time. The most important one is Instant, which denotes a point in time, regardless of time zone. A map with the other types:

You can create instances of any one of them with static methods from their classes, e.g. Instant.from(...), Instant.parse(...) or LocalTime.browser(). Similar methods exist on all Globol data types. Once a data type is instantiated, there are methods for converting between them and doing calculations and comparisons with them.

Below is a dedicated description for each data type.

Instant

This is a moment in time, a timestamp. Is equivalent to a number of (milli)seconds since the epoch.

ZonedDateTime

A date with a time and a time zone offset, e.g. 2020-01-20T19:34Z+01. A ZonedDateTime implies one Instant, but one Instant can be represented in at least 24 ZonedDateTimes (one for each time zone).

LocalDateTime

A date and a time together, but without a zone, e.g. 2020-01-20T19:34

LocalDate

A date without a time, e.g. 2020-01-20

LocalTime

A time without a date, e.g. one LocalTime can mean 18:34 or 6:34 PM, depending on how you format it in string form.

Duration

A fixed length of physical time.

ZoneId & ZoneOffset

These represent timezones. The difference between ZoneId and ZoneOffset is as follows: ZoneId represents something like Europe/Amsterdam, which can have a ZoneOffset of +1 in the winter and +2 in the summer.

Future work

Time zone information

Browsers provide time zone information, but the support is still limited/incomplete. Therefore we'd like to make it optional to include the moment-timezone dependency. This can be done by make a separate NPM dependency called globol-timezone which, when included, runtime-enriches Globol with the moment-timezone time zone information. When it's left out globol would rely on the time zone information supplied by the browser.

Feedback

If something is missing from this library that makes it not fit your use case today, or if you find a bug that spoils it for you, don't hesitate to create an Issue (just a stub is better than nothing!) or a Pull Request. At this moment, the library is not at 1.0 yet and is organically growing to suit the use cases we run into first! Any feedback and/or contribution is sincerely appreciated.

License

The content of this project is licensed under the MIT license.