Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Holidays.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
13 changes: 2 additions & 11 deletions docs/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ For country codes / divisions / subdivisions - ISO 3166-2: <br>
<http://www.unicode.org/cldr/charts/30/supplemental/territory_subdivisions.html>

For timezones: <br>
<https://github.com/moment/moment-timezone/blob/develop/data/meta/latest.json>
<https://github.com/moment/luxon/blob/master/docs/zones.md>

For language codes ISO 639-1: <br>
<http://www.unicode.org/cldr/charts/30/supplemental/language_territory_information.html>
Expand Down Expand Up @@ -152,7 +152,7 @@ To specify the rules to calculate the holidays per country, state, region is as

- `<county/state/region>` is the shortcode to identify country, state or region
- `<lang_?>` represents the ISO 639-1 language code for the assigned language.
- `<timezone_?>` is a string representing the timezone. See file `data/meta/latest.json` of [moment-timezone][]
- `<timezone_?>` is a string representing the timezone
- `<rule_?>` is the rule for that holiday

## Citations, Sources, and Attribution
Expand Down Expand Up @@ -698,15 +698,6 @@ npm run yaml

This concatenates the two files `holidays.yaml` and `names.yaml` and generates the JSON file.

# References

<!-- !ref -->

* [moment-timezone][moment-timezone]

<!-- ref! -->

[moment-timezone]: https://github.com/moment/moment-timezone

----
End of file
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
106 changes: 54 additions & 52 deletions src/Equinox.js
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 1 addition & 1 deletion src/Holidays.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions test/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import moment from 'moment-timezone'
import { DateTime } from 'luxon'
import { pad0 } from '../src/internal/utils.js'

export function toIso (date) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down