locale-timezone-date
v5.0.1
Published
JavaScript local time zone Date module
Downloads
2
Readme
localeTimezoneDate
JavaScript locale time zone Date module
const LocaleTimezoneDate = require("locale-timezone-date");
const LocaleTimezoneDate = require("locale-timezone-date");
//
//
let localeDate = new LocaleTimezoneDate();
console.log(localeDate instanceof Date);
// true
//
//
/////////////////////////////////////////////////
// toLocaleISOString
//
console.log(localeDate.toLocaleISOString());
// "2021-04-09T09:15:43.062+0200"
console.log(new Date(localeDate.toLocaleISOString()).toISOString() === localeDate.toISOString());
// true
//
//
/////////////////////////////////////////////////
// toFalsyLocaleISOString
//
console.log(localeDate.toFalsyLocaleISOString());
// "2021-04-09T09:15:43.062Z"
console.log(new Date(localeDate.toFalsyLocaleISOString()).toISOString() === localeDate.toISOString());
// false
//
//
/////////////////////////////////////////////////
// yyyymmdd - TIME UTC0 - HOUR 0
//
const H00_Z = "2020-08-06T00:00:00.000Z";
localeDate = new LocaleTimezoneDate(H00_Z);
console.log(localeDate.yyyymmdd());
// "2020-08-06"
console.log(localeDate.getUTCOffset());
// { hhmm: '+0200', hour: 2 }
//
// yyyymmdd - TIME UTC0 - HOUR 22
//
const H22_Z = "2020-08-06T22:00:00.000Z";
localeDate = new LocaleTimezoneDate(H22_Z);
console.log(localeDate.yyyymmdd());
// "2020-08-07"
console.log(localeDate.getUTCOffset());
// { hhmm: '+0200', hour: 2 }
//
//
/////////////////////////////////////////////////
// yyyymmdd - LOCALE TIME - HOUR 0
//
const H00_UTC2 = "2020-08-06T00:00:00.000+0200";
localeDate = new LocaleTimezoneDate(H00_UTC2);
console.log(localeDate.yyyymmdd());
// "2020-08-06"
console.log(localeDate.getUTCOffset());
// { hhmm: '+0200', hour: 2 }
//
// yyyymmdd - LOCALE TIME - HOUR 22
//
const H22_UTC2 = "2020-08-06T22:00:00.000+0200";
localeDate = new LocaleTimezoneDate(H22_UTC2);
console.log(localeDate.yyyymmdd());
// "2020-08-06"
console.log(localeDate.getUTCOffset());
// { hhmm: '+0200', hour: 2 }
//
//
/////////////////////////////////////////////////
// msStartOfYear - START OF THE YEAR - LOCALE
//
localeDate = new LocaleTimezoneDate();
const startOfYearLocale = localeDate.startOfYear({ ms: false });
console.log(startOfYearLocale.toISOString());
// "2020-12-31T23:00:00.000Z"
console.log(startOfYearLocale.toLocaleISOString());
// "2021-01-01T00:00:00.000+0100"
//
// msStartOfYear - START OF THE YEAR - NOT LOCALE
//
const startOfYear = localeDate.startOfYear({ ms: false, locale: false });
console.log(startOfYear.toISOString());
// "2021-01-01T00:00:00.000Z"
console.log(startOfYear.toLocaleISOString());
// "2021-01-01T01:00:00.000+0100"
//
//
/////////////////////////////////////////////////
// msStartOfMonth - START OF THE MONTH - LOCALE
//
const startOfMonthLocale = localeDate.startOfMonth({ ms: false });
console.log(startOfMonthLocale.toISOString());
// "2021-03-31T22:00:00.000Z"
console.log(startOfMonthLocale.toLocaleISOString());
// "2021-04-01T00:00:00.000+0200"
//
// msStartOfMonth - START OF THE MONTH - NOT LOCALE
//
const startOfMonth = localeDate.startOfMonth({ ms: false, locale: false });
console.log(startOfMonth.toISOString());
// "2021-04-01T00:00:00.000Z"
console.log(startOfMonth.toLocaleISOString());
// "2021-04-01T02:00:00.000+0200"
//
//
/////////////////////////////////////////////////
// msStartOfDate - START OF THE DAY - LOCALE
//
const startOfDateLocale = localeDate.startOfDate({ ms: false });
console.log(startOfDateLocale.toISOString());
// "2021-04-08T22:00:00.000Z"
console.log(startOfDateLocale.toLocaleISOString());
// "2021-04-09T00:00:00.000+0200"
//
// msStartOfDate - START OF THE DAY - NOT LOCALE
//
const startOfDate = localeDate.startOfDate({ ms: false, locale: false });
console.log(startOfDate.toISOString());
// "2021-04-09T00:00:00.000Z"
console.log(startOfDate.toLocaleISOString());
// "2021-04-09T02:00:00.000+0200"