@js-sugar/date
Version:
A multi-calendar, tree-shakable, extensible, immutable and lightweight date library for JavaScript
155 lines (154 loc) • 4.42 kB
TypeScript
/**
* @category Core
* @module DateTime
*/
import { Calendar } from './calendar';
import { Locale } from './locale';
import { Zone } from './zone';
import { CalendarSpecifier, DateTimeUnits, LocaleSpecifier, ZoneSpecifier } from './common';
/** DateTime create options. */
export interface DateTimeCreationOptions {
/** Calendar specifier */
calendar?: CalendarSpecifier;
/** Zone specifier */
zone?: ZoneSpecifier;
/** Locale specifier */
locale?: LocaleSpecifier;
}
/** DateTime configuration. */
export interface DateTimeConfiguration {
calendar: Calendar;
zone: Zone;
locale: Locale;
}
/**
* JS-Sugar DateTime.
* @public
*/
export declare class DateTime {
#private;
/**
* Creates a new DateTime object.
* @constructor
*/
constructor();
constructor(opts: DateTimeCreationOptions);
constructor(year: number, month: number, day?: number, hour?: number, minute?: number, second?: number, ms?: number, opts?: DateTimeCreationOptions);
constructor(opts: DateTimeCreationOptions, year: number, month: number, day?: number, hour?: number, minute?: number, second?: number, ms?: number);
constructor(timestamp: number, opts?: DateTimeCreationOptions);
/**
* Gets the year.
* @public
*/
get year(): number;
/**
* Gets the month (1-12).
* @public
*/
get month(): number;
/**
* Gets the day of the month (1 to 31).
* @public
*/
get day(): number;
/**
* Gets the hour of the day (0 to 23).
* @public
*/
get hour(): number;
/**
* Gets the minute of the hour (0 to 59).
* @public
*/
get minute(): number;
/**
* Gets the second of the minute (0 to 59).
* @public
*/
get second(): number;
/**
* Gets the millisecond of the second (0 to 999).
* @public
*/
get ms(): number;
/**
* Gets the timestamp of this object.
* @public
* @description This value is usually the number of milliseconds since January 1, 1970 (EPOCH) and
* it can be a positive or negetive number (it depends on the implementation of the Calendar).
*/
get ts(): number;
/**
* Returns a clone of the configurations of this object (calandar, zone and locale).
* @public
*/
get config(): DateTimeConfiguration;
/**
* Adds a period of time to this DateTime and returns the resulting DateTime.
* @public
* @param units DateTimeUnits
*/
add(units: DateTimeUnits): DateTime;
/**
* Subtracts a period of time from this DateTime and returns the resulting DateTime.
* @public
* @param units DateTimeUnits
*/
subtract(units: DateTimeUnits): DateTime;
/**
* Gets the locale of a DateTime.
* @public
*/
get locale(): Locale;
/**
* Returns a new DateTime equivalent with this DateTime but with a different Locale
* @public
*/
toLocale(locale: LocaleSpecifier): DateTime;
/**
* Returns the zone of this DateTime object
* @public
*/
get zone(): Zone;
/**
* Returns a new DateTime equivalent with this DateTime but with UTC as time-zone
* @public
*/
toUtc(): DateTime;
/**
* Returns a new DateTime equivalent with this DateTime but with local time-zone
* @public
*/
toLocal(): DateTime;
/**
* Returns a new DateTime equivalent with this DateTime but with a different Zone
* @public
*/
toZone(zone: ZoneSpecifier): DateTime;
/**
* Returns a new DateTime equivalent with this DateTime but with a different Calendar
* @public
* @param calendar CalendarSpecifier
*/
to(calendar: CalendarSpecifier): DateTime;
/**
* Gets the calendar of this DateTime
* @public
*/
get calendar(): Calendar;
/**
* Clones this DateTime with overwriten new unit values.
* @public
*/
clone(newUnits?: DateTimeUnits): DateTime;
/**
* Clones this DateTime with "time units" (hour, minute, second, ms) set to zero.
* @public
*/
get date(): DateTime;
/**
* Returns the units of this DateTime object.
* @public
*/
toObject(): DateTimeUnits;
}