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

@bitchcraft/timestamp

v0.1.0

Published

RFC3339 / ISO8601 String from Date

Downloads

6

Readme

@bitchcraft/timestamp

Output RFC3339 / ISO8601 String from Date

Installation

$ yarn add @bitchcraft/timestamp
$ npm install -P @bitchcraft/timestamp

Usage

timestampFromDate

timestampFromDate(date: Date, tz: Timezone): string

Outputs an RFC3339 / ISO8601 string from a date. The date is converted to the specified output TZ, or UTC (Z / +0000) if not provided.

| @param | Type | Default value | Description | |:-------- |:-------- |:----------------- |:---------------------------- | | date | Date | required | | | timezone | Timezone | new Timezone('Z') | the TZ for the output string |

ES6 example

import { timestampFromDate, Timezone } from '@bitchcraft/timestamp';

const utcTimezone = new Timezone('Z');
const currentDate = new Date();
const currentUtcTimestamp = timestampFromDate(currentDate, utcTimezone);

console.log(`The current UTC timestamp is ${currentUtcTimestamp}.`);

ES5 example

var { timestampFromDate, Timezone } = require('@bitchcraft/timestamp');

var utcTimezone = new Timezone('Z');
var currentDate = new Date();
var currentUtcTimestamp = timestampFromDate(currentDate, utcTimezone);

console.log('The current UTC timestamp is %s.', currentUtcTimestamp);

Timezone

new Timezone(tz: string): Timezone

A timezone helper class.

Parameters

| @param | Type | Description | |:------ |:------ |:---------------------------------------------------------------------- | | tz | string | Timezone string, e. g. 'Z', 'GMT+3', '-0230'. Default value is '+0000' |

Properties and methods

| | | Return type | Description | | ------- | ------------------------------------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | @prop | value | string | ISO timezone string, e. g. 'Z', '+0800', '-1130' | | @prop | hours | number (unsigned int) | integer representation of the hours part of the timezone. See toNumber() to get an integer representation of the timezone. | | @prop | minutes | number (unsigned int) | integer representation of the minutes part of the timezone. See toNumber() to get an integer representation of the timezone. | | @prop | sign | number (signed int) | number representation of the prefix of the timenzone. 1 for positive, 0 for UTC and -1 for negative timezone offset. | | @prop | prefix | string | string represenationg of the prefix, e. g. '+', 'Z' or '-' | | @method | toString() | string | returns value | | @method | toNumber(option: string, invertSign: boolean) | number (signed int) | returns value as a number. The scale is provided in option (defaults to 'MINUTES'). Set invertSign to true for sign symmetry with Date.getTimezoneOffset() (defaults to false). Valid values for option are: 'MILLENIA', 'CENTURIES', 'DECADES', 'YEARS', 'QUARTERS', 'MONTHS', 'WEEKS', 'DAYS', 'HOURS', 'MINUTES', 'SECONDS', 'MILLISECONDS'. | | @static | fromNumber(offset: number, invertSign: boolean) | Timezone | Create a timezone instance from a number (in minutes) | | @static | getPrefixFor(timezoneString: string) | string | Return cleaned prefix from timezone string. returns '+' for '+', '-' for '-'/'–'/'—' and 'Z' for everything else | | @static | getPrefixForSign(sign: number) | string | Return string prefix for number. See @prop prefix | | @static | getSignForPrefix(timezoneString: string) | number | Return number sign for string. See @prop sign |

Help and feedback

Please file issues in Github

Contribute

We are open for PRs. Please respect to the linting rules.

License

Timestamp is free software und the BSD-3-Clause (see LICENSE.md).

Contributors