UNPKG

date-vir

Version:

Easy and explicit dates and times.

69 lines (68 loc) 1.63 kB
import { toUtcIsoString } from '../formatting/timestamp.js'; import { createFullDate } from '../full-date/create-full-date.js'; import { userTimezone, utcTimezone } from '../timezone/timezones.js'; /** * Get the time right now as a UTC ISO. * * @category Now * @example * * ```ts * import {getNowInIsoString} from 'date-vir'; * * getNowInIsoString(); * ``` */ export function getNowInIsoString() { /** * The time zone doesn't matter here because the ISO string will be identical for a given date * no matter what its timezone is. */ return toUtcIsoString(getNowFullDate(utcTimezone)); } /** * Get the time right now as a {@link FullDate} represented in the current user's timezone. * * @category Now * @example * * ```ts * import {getNowInUserTimezone} from 'date-vir'; * * getNowInUserTimezone(); * ``` */ export function getNowInUserTimezone() { return getNowFullDate(userTimezone); } /** * Get the time right now as a {@link FullDate} represented in the UTC timezone. * * @category Now * @example * * ```ts * import {getNowInUtcTimezone} from 'date-vir'; * * getNowInUtcTimezone(); * ``` */ export function getNowInUtcTimezone() { return getNowFullDate(utcTimezone); } /** * Get the time right now as a {@link FullDate} represented in the given timezone. * * @category Now * @example * * ```ts * import {getNowFullDate, utcTimezone, timezones} from 'date-vir'; * * getNowFullDate(utcTimezone); * getNowFullDate(timezones['Australia/Brisbane']); * ``` */ export function getNowFullDate(timezone) { return createFullDate(Date.now(), timezone); }