UNPKG

@storm-stack/date-time

Version:

This package includes a DateTime class, various utility functions for working with dates and times, and a number of formatting options.

100 lines (99 loc) 3.3 kB
import { Temporal } from "@js-temporal/polyfill"; import { type JsonValue } from "@storm-stack/serialization"; import { ValidationDetails } from "@storm-stack/types"; import type { DateTimeInput, DateTimeOptions } from "./storm-date-time"; import { StormDateTime } from "./storm-date-time"; /** * Serializes a StormTime into a string * * @param date - The time to serialize * @returns The serialized time */ export declare function serializeStormTime(date: StormTime): string; /** * Deserializes a string into a StormTime * * @param utcString - The time to deserialize * @returns The deserialized time */ export declare function deserializeStormTime(utcString: JsonValue): StormTime; /** * A wrapper of the and Date class used by Storm Software to provide Date-Time values * * @decorator `@Serializable()` * @class StormTime */ declare class StormTime extends StormDateTime { /** * The current function returns a new DateTime object with the current date and time * @returns A new instance of DateTime with the current date and time. */ static now(): number; /** * The current function returns a new DateTime object with the current date and time * @returns A new instance of DateTime with the current date and time. */ static current(): StormTime; /** * Validate the input time value * * @param dateTime - The date value to validate * @returns A boolean representing whether the value is a valid *date-time* */ static validate(value?: DateTimeInput): ValidationDetails | null; /** * Creates a new instance of DateTime from a string with a specified format. * * @param time - The input value used to determine the current time * @param options - The options to use * @returns A new instance of StormTime with the time provided in the time parameter. */ static create(time?: DateTimeInput, options?: DateTimeOptions): StormTime; constructor(dateTime?: DateTimeInput, options?: DateTimeOptions); /** * A function that validates the current Time object * * @returns A ValidationDetails object if the Time object is invalid, otherwise null */ validate(): ValidationDetails | null; /** * Gets the year, using local time. */ getFullYear(): number; /** * Gets the year using Universal Coordinated Time (UTC). */ getUTCFullYear(): number; /** * Gets the month, using local time. */ getMonth(): number; /** * Gets the month of a Date object using Universal Coordinated Time (UTC). */ getUTCMonth(): number; /** * Gets the day-of-the-month, using local time. */ getDate(): number; /** * Gets the day-of-the-month, using Universal Coordinated Time (UTC). */ getUTCDate(): number; /** * Gets the day of the week, using local time. */ getDay(): number; /** * Gets the day of the week using Universal Coordinated Time (UTC). */ getUTCDay(): number; /** * It returns the duration between two dates. * * @param dateTimeTo - DateTime = DateTime.current * @returns A duration object. */ getDuration(dateTimeTo?: StormTime): Temporal.Duration; } export { StormTime };