diff --git a/docs/Holidays.md b/docs/Holidays.md index 6815828..07fe8a5 100644 --- a/docs/Holidays.md +++ b/docs/Holidays.md @@ -197,7 +197,7 @@ sets timezone **Parameters** -**timezone**: `String`, see `moment-timezone` +**timezone**: `String`, see `luxon zone` if `timezone` is `undefined`, then all dates are considered local dates diff --git a/docs/specification.md b/docs/specification.md index 498a688..f4a629e 100644 --- a/docs/specification.md +++ b/docs/specification.md @@ -109,7 +109,7 @@ For country codes / divisions / subdivisions - ISO 3166-2:
For timezones:
- + For language codes ISO 639-1:
@@ -152,7 +152,7 @@ To specify the rules to calculate the holidays per country, state, region is as - `` is the shortcode to identify country, state or region - `` represents the ISO 639-1 language code for the assigned language. -- `` is a string representing the timezone. See file `data/meta/latest.json` of [moment-timezone][] +- `` is a string representing the timezone - `` is the rule for that holiday ## Citations, Sources, and Attribution @@ -698,15 +698,6 @@ npm run yaml This concatenates the two files `holidays.yaml` and `names.yaml` and generates the JSON file. -# References - - - -* [moment-timezone][moment-timezone] - - - -[moment-timezone]: https://github.com/moment/moment-timezone ---- End of file diff --git a/package.json b/package.json index 2d4e9ca..9604f96 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "date-chinese": "^2.1.3", "date-easter": "^1.0.1", "deepmerge": "^4.2.2", - "moment-timezone": "^0.5.34" + "luxon": "^2.4.0" }, "devDependencies": { "c8": "^7.11.2", diff --git a/src/Equinox.js b/src/Equinox.js index 22de201..c14cfae 100644 --- a/src/Equinox.js +++ b/src/Equinox.js @@ -1,63 +1,65 @@ -import { solstice, julian, planetposition } from 'astronomia' -import { vsop87Bearth } from './vsop87Bearth.js' - -import moment from 'moment-timezone' +import { julian, planetposition, solstice } from 'astronomia' import CalDate from 'caldate' +import { DateTime } from 'luxon' import CalEvent from './CalEvent.js' +import { vsop87Bearth } from './vsop87Bearth.js' + const earth = new planetposition.Planet(vsop87Bearth) export default class Equinox extends CalEvent { - /** - * @param {object} [opts] - * @param {string} opts.season - type of season (spring|summer|autumn|winter) - * @param {number|string} opts.offset - offset in days - */ - constructor (opts) { - opts = opts || {} - super(opts) - - this._season = opts.season - this._timezone = opts.timezone || 'GMT' - } - - inYear (year) { - let jde - switch (this._season) { - case 'march': { - jde = solstice.march2(year, earth) - break - } - case 'june': { - jde = solstice.june2(year, earth) - break - } - case 'september': { - jde = solstice.september2(year, earth) - break - } - case 'december': { - jde = solstice.december2(year, earth) - break - } - } + /** + * @param {object} [opts] + * @param {string} opts.season - type of season (spring|summer|autumn|winter) + * @param {number|string} opts.offset - offset in days + */ + constructor(opts) { + opts = opts || {} + super(opts) - const str = new julian.Calendar().fromJDE(jde).toDate().toISOString() - let date - if (/^[+-]\d{2}:\d{2}?$/.test(this._timezone)) { // for '+08:00' formats - date = moment(str).utcOffset(this._timezone) - } else { // for 'Asia/Shanghai' formats - date = moment(str).tz(this._timezone) // move to timezone + this._season = opts.season + this._timezone = opts.timezone || 'GMT' } - const floorDate = { - year: year, - month: date.month() + 1, - day: date.date() - } + inYear(year) { + let jde + switch (this._season) { + case 'march': { + jde = solstice.march2(year, earth) + break + } + case 'june': { + jde = solstice.june2(year, earth) + break + } + case 'september': { + jde = solstice.september2(year, earth) + break + } + case 'december': { + jde = solstice.december2(year, earth) + break + } + } + + const str = new julian.Calendar().fromJDE(jde).toDate().toISOString() + let date + if (/^[+-]\d{2}:\d{2}?$/.test(this._timezone)) { + // for '+08:00' formats + date = DateTime.fromISO(str, { setZone: true }) + } else { + // for 'Asia/Shanghai' formats + date = DateTime.fromISO(str, { zone: this._timezone }) // move to timezone + } - const d = new CalDate(floorDate).setOffset(this.offset) - this.dates.push(d) - return this - } + const floorDate = { + year: year, + month: date.month, + day: date.day, + } + + const d = new CalDate(floorDate).setOffset(this.offset) + this.dates.push(d) + return this + } } diff --git a/src/Holidays.js b/src/Holidays.js index 3713dcd..6ddbfdd 100644 --- a/src/Holidays.js +++ b/src/Holidays.js @@ -320,7 +320,7 @@ export class Holidays { /** * sets timezone - * @param {String} timezone - see `moment-timezone` + * @param {String} timezone - see `luxon zone` * if `timezone` is `undefined`, then all dates are considered local dates */ setTimezone (timezone) { diff --git a/test/helpers.js b/test/helpers.js index 464f548..f6c8082 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -1,4 +1,4 @@ -import moment from 'moment-timezone' +import { DateTime } from 'luxon' import { pad0 } from '../src/internal/utils.js' export function toIso (date) { @@ -34,11 +34,13 @@ function toString (date) { return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds } -export function moveToTimezone (date, timezone) { +export function moveToTimezone(date, timezone) { if (!timezone) { - return date + return date } - return new Date(moment.tz(toString(date), timezone).format()) + return DateTime.fromJSDate(date) + .setZone(timezone, { keepCalendarTime: true }) + .toJSDate() } export function localDate (str) { diff --git a/types/index.d.ts b/types/index.d.ts index ae2844c..57cb0ef 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -178,7 +178,7 @@ declare module 'date-holidays-parser' { /** * sets timezone - * @param timezone - see `moment-timezone` + * @param timezone - see `luxon zone` * if `timezone` is `undefined`, then all dates are considered local dates */ setTimezone(timezone: string): void;