0.1.0 • Published 6 years ago

@bitchcraft/timestamp v0.1.0

Weekly downloads
1,466
License
BSD-3-Clause
Repository
github
Last release
6 years ago

@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.

@paramTypeDefault valueDescription
dateDaterequired
timezoneTimezonenew 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

@paramTypeDescription
tzstringTimezone string, e. g. 'Z', 'GMT+3', '-0230'. Default value is '+0000'

Properties and methods

Return typeDescription
@propvaluestringISO timezone string, e. g. 'Z', '+0800', '-1130'
@prophoursnumber (unsigned int)integer representation of the hours part of the timezone. See toNumber() to get an integer representation of the timezone.
@propminutesnumber (unsigned int)integer representation of the minutes part of the timezone. See toNumber() to get an integer representation of the timezone.
@propsignnumber (signed int)number representation of the prefix of the timenzone. 1 for positive, 0 for UTC and -1 for negative timezone offset.
@propprefixstringstring represenationg of the prefix, e. g. '+', 'Z' or '-'
@methodtoString()stringreturns value
@methodtoNumber(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'.
@staticfromNumber(offset: number, invertSign: boolean)TimezoneCreate a timezone instance from a number (in minutes)
@staticgetPrefixFor(timezoneString: string)stringReturn cleaned prefix from timezone string. returns '+' for '+', '-' for '-'/'–'/'—' and 'Z' for everything else
@staticgetPrefixForSign(sign: number)stringReturn string prefix for number. See @prop prefix
@staticgetSignForPrefix(timezoneString: string)numberReturn 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