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

vega-time

v2.1.2

Published

JavaScript date/time utilities for Vega.

Downloads

645,175

Readme

vega-time

JavaScript date-time utilities for Vega. Provides a set of helper methods for working with date objects (or, equivalently, with UNIX timestamps).

API Reference

Time Units

The date-time utilities support a set of pre-defined time units. A single unit value is one of the following strings:

  • 'year' - Gregorian calendar years.
  • 'quarter' - Three-month intervals, starting in one of January, April, July, and October.
  • 'month' - Calendar months (January, February, etc.).
  • 'date' - Calendar day of the month (January 1, January 2, etc.).
  • 'week' - Sunday-based weeks. Days before the first Sunday of the year are considered to be in week 0, the first Sunday of the year is the start of week 1, the second Sunday week 2, etc..
  • 'day' - Day of the week (Sunday, Monday, etc.).
  • 'dayofyear' - Day of the year (1, 2, ..., 365, etc.).
  • 'hours' - Hours of the day (12:00am, 1:00am, etc.).
  • 'minutes' - Minutes in an hour (12:00, 12:01, etc.).
  • 'seconds' - Seconds in a minute (12:00:00, 12:00:01, etc.).
  • 'milliseconds' - Milliseconds in a second.

Multiple units can be listed in an array to indicate desired intervals of time. For example, ['year', 'month', 'date'] indicates chronological time sensitive to year, month, and date (but not to hours, minutes, or seconds). The specifier ['month', 'date'] is sensitive to month and date, but not year, which can be useful for binning time values to look at seasonal patterns only.

# vega.timeUnits(units) <>

Returns a standardized and sorted specifier for the given units, which must be an array of one or more valid time unit strings. The returned array contains the same units, sorted in decreasing over of unit size, such that the most granular unit is last (for example, ['year', 'month', 'date']). This method throws an error if the units array is empty, contains an invalid unit, or contains incompatible units. Specifically, the 'quarter', 'month', and 'date' units can not be used in conjunction with the 'week' or 'day' units.

# vega.timeUnitSpecifier(units[, specifiers]) <>

Returns a time format specifier string for the given time units. The optional specifiers object provides a set of desired specifier sub-strings for customizing the resulting time formats. The specifiers object may contain keys for both single time units ("year") and time unit sequences ("year-month-date"). This method will first standardize the input time units using the timeUnits method. It will then search, starting from the beginning of the units array, for the largest matching sequence defined in the specifiers object. Matching entries are then concatenated together, and the resulting string is whitespace-trimmed and returned.

If no specifiers object is provided, the following defaults are used:

{
  "year": "%Y ",
  "year-month": "%Y-%m ",
  "year-month-date": "%Y-%m-%d ",
  "quarter": "Q%q ",
  "month": "%b ",
  "date": "%d ",
  "week": "W%U ",
  "day": "%a ",
  "hours": "%H:00",
  "hours-minutes": "%H:%M",
  "minutes": "00:%M",
  "seconds": ":%S",
  "milliseconds": ".%L"
}

If a specifiers object is provided, its values are merged with the defaults above. As a result, for complete control callees may wish to override the multi-unit "year-month", "year-month-date", and "hours-minutes" entries in addition to any individual unit entries. The input specifiers object can use a null value to invalidate an entry in the defaults.

# vega.timeBin(options) <>

Determine a temporal binning scheme, for example to create a histogram. Based on the options provided given, this method will search over a space of possible time unit bins, applying constraints such as the maximum number of allowable bins. Given a set of options (see below), returns an object describing the binning scheme, in terms of units and step properties. These values can then be used as input to the timeFloor or utcFloor methods.

The supported options properties are:

  • extent: (required) A two-element ([min, max]) array indicating the date range over which the bin values are defined.
  • maxbins: The maximum number of allowable bins (default 40). There will often be fewer bins as the domain gets sliced at "nicely" rounded values.

Local Time Utilities

# vega.timeFloor(units[, step]) <>

Returns a function that performs flooring (truncation) of input dates to given time units in the local timezone. The units argument must be an array of valid time unit strings, for example ['year', 'month'] or ['week', 'date']. The optional step argument (default 1) indicates the number of time unit steps (of the smallest provided unit) to include as part of the truncation scheme. For example, utcFloor(['quarter']) is equivalent to utcFloor(['month'], 3).

# vega.timeInterval(unit) <>

Returns a d3-time interval for the given time unit in the local timezone.

# vega.timeOffset(unit, date[, step]) <>

Returns a new Date instance that offsets the given date by the specified time unit in the local timezone. The optional step argument indicates the number of time unit steps to offset by (default 1).

# vega.timeSequence(unit, start, stop[, step]) <>

Returns an array of Date instances from start (inclusive) to stop (exclusive), with each entry separated by the given time unit in the local timezone. The optional step argument indicates the number of time unit steps to take between each sequence entry (default 1).

# vega.dayofyear(date) <>

Returns the one-based day of the year for the given date, which should be either a Date object or timestamp value.

# vega.week(date) <>

Returns the week number of the year for the given date, which should be either a Date object or timestamp value. This function assumes Sunday-based weeks. Days before the first Sunday of the year are considered to be in week 0, the first Sunday of the year is the start of week 1, the second Sunday week 2, etc..

UTC Time Utilities

# vega.utcFloor(units[, step]) <>

Returns a function that performs flooring (truncation) of input dates to given time units in Coordinated Universal Time (UTC). The units argument must be an array of valid time unit strings, for example ['year', 'month'] or ['week', 'date']. The optional step argument (default 1) indicates the number of time unit steps (of the smallest provided unit) to include as part of the truncation scheme. For example, utcFloor(['quarter']) is equivalent to utcFloor(['month'], 3).

# vega.utcInterval(unit) <>

Returns a d3-time interval for the given time unit in Coordinated Universal Time (UTC).

# vega.utcOffset(unit, date[, step]) <>

Returns a new Date instance that offsets the given date by the specified time unit in Coordinated Universal Time (UTC). The optional step argument indicates the number of time unit steps to offset by (default 1).

# vega.utcSequence(unit, start, stop[, step]) <>

Returns an array of Date instances from start (inclusive) to stop (exclusive), with each entry separated by the given time unit in Coordinated Universal Time (UTC). The optional step argument indicates the number of time unit steps to take between each sequence entry (default 1).

# vega.utcdayofyear(date) <>

Returns the one-based day of the year for the given date in Coordinated Universal Time (UTC), which should be either a Date object or timestamp value.

# vega.utcweek(date) <>

Returns the week number of the year for the given date in Coordinated Universal Time (UTC), which should be either a Date object or timestamp value. This function assumes Sunday-based weeks. Days before the first Sunday of the year are considered to be in week 0, the first Sunday of the year is the start of week 1, the second Sunday week 2, etc..