commenthol / date-holidays-parser Goto Github PK
View Code? Open in Web Editor NEWparser for worldwide holidays
License: ISC License
parser for worldwide holidays
License: ISC License
Hello,
We have a timezone system based in different customers within the same codebase. Each customer has its timezone set against itself and we use it together with moment-timezone to deal with their correct and exact time and days (start of, end of and exactly time for each time).
The issue happens when the holiday and the timezone offsets the zulu time per one day, e.g.:
01-01-2018
is a holiday2017-12-31T13:00:00.000Z
const year = toYear(date);
which returns 2017if (hd[j] && date >= hd[j].start && date < hd[j].end)
In other words, given:
const hd = new Holidays('AU');
const holiday = hd.isHoliday(new Date("2017-12-31T13:00:00.000Z"));
holiday should be
{
date: '2018-01-01 00:00:00',
start: 2017-12-31T13:00:00.000Z,
end: 2018-01-01T13:00:00.000Z,
name: "New Year's Day",
type: 'public'
}
However it's returning that this is not a holiday.
can I please check in order to understand this library - it contains a test with the code:
it('02-06 and if saturday then previous friday if sunday then next monday in 2016', function () {
const fn = new DateFn('02-06 14:00 and if saturday then previous friday 16:45 if sunday then next monday PT12H')
const res = fn.inYear(2016).get()
const exp = [{
date: '2016-02-06 14:00:00',
start: 'sat 2016-02-06 14:00',
end: 'sun 2016-02-07 00:00'
}, {
date: '2016-02-05 16:45:00',
start: 'fri 2016-02-05 16:45',
end: 'sat 2016-02-06 00:00',
substitute: true
}]
assert.deepStrictEqual(fixResult(res), exp)
})
my take on PT12H would be a timespan/duration of 12 hours, in which case the expected end
dates should be 'sun 2016-02-07 02:00' and 'sat 2016-02-06 04:45' respectively. Is this test set up correctly?
Hi, I might be missing something.
Jan 1st, 2022 is Saturday. The rule is "01-01 and if saturday,sunday then next monday"
so the holiday is actually on Jan 3rd.
However, the following code returns BOTH the Saturday AND the Monday as items 0 and 1 in the hols array and the isHoliday(hols[0].start)
returns Jan 1st as being the holiday.
const holsObj = new Holidays('AU', 'NSW')
const hols = holsObj.getHolidays('2022')
const isHol = holsObj.isHoliday(hols[0].start)
Using year 2025
, where Jan 1st on Wednesday, it only returns the one date, as expected.
Is there a way to get the actual holiday applicable in that year?
Thanks for a great library,
Murray
A holiday name may change over time and get replaced or discontinued.
The same applies if a holiday is effective from a certain timestamp on.
Currently this is attributed by the active
array using {to, from}
.
For renaming a name this then will case a duplication of the rule name which then is resolved with a numbering scheme using #1
.
This is not ideal.
It is therefore proposed to introduce a set of new rules:
<rule> since YYYY(-MM-DD)?
means that the rule is effective since year
<rule> prior to YYYY(-MM-DD)?
means that the rule is effective prior to year
<rule> since YYYY(-MM-DD)? and prior to YYYY(-MM-DD)?
means that the rule is effective since year and prior to another year
See commenthol/date-holidays#164 .
The isHolidays method may resolve to a list of holiday events in case that two holiday rules match the same day.
Currently only a single date is returned.
Therefor the method should correctly return a list of holidays, which will introduce a breaking change.
Error:
Exception while invoking method 'getHolidays' TypeError: o.str.substr is not a function
at Parser._shorten (/app/node_modules/date-holidays-parser/lib/Parser.js:192:21)
with the country 'AT':
const Holidays = require('date-holidays');
let holidays = new Holidays();
holidays.init('AT');
holidays.getHolidays(2020); // ERROR
After some debugging:
key: "_shorten",
value: function _shorten(o, cap0) {
console.log({ o, cap0 });
o.str = o.str.substr(cap0.length, o.str.length);
}
it seems like that o
and cap0
are both function
s!!
Please fix, this is very annoying as this completely breaks the whole library for me 😢
As of v3.3.0, the import destination for astronomia
in vsop87Bearth.cjs
seems to have changed.
v3.2.4
https://unpkg.com/[email protected]/lib/vsop87Bearth.cjs
var _vsop87Bearth = require('astronomia/lib/data/vsop87Bearth.cjs');
v3.3.0
https://unpkg.com/[email protected]/lib/vsop87Bearth.cjs
var _vsop87Bearth = require('astronomia/data/vsop87Bearth');
This caused syntax errors in module systems that use CJS, such as Jest.
Currently all weekdays for parsing rules need to be typed in lower case. This might lead to confusions.
This should be possible to write weekdays correctly being the first letter in uppercase.
The Parser should detect weekdays correctly e.g. Monday, ..., Sunday within the rules.
Current rules should not be affected by such change.
Add a new rule which allows to set a holiday only if falling on certain weekday(s).
Rule is required for Swiss holiday 12-26 "Stefanstag" which is a holiday in some Cantones if not on Friday or Monday.
Moment is now considered a legacy project:
https://www.npmjs.com/package/moment
There have been multiple PR's already:
#53
#48
#2
It would be nice if @commenthol could clarify which newer library should best be used.
The library is not usable with Typescript at the moment.
Include
"exports": {
// ...
"types": "./types"
}
in the package.json
, since right now the types are not exported and not usable. All the types in thy types
directory are duplicated in the dates-holidays
library for some reason and exported there. However, if one wants to use just the parser itself, types are not exported at all.
Hi there,
hd.getDayOff() returns undefined (country 'CH', 'GE'))
setDayOff() does not exist, and can't find any documentation related. Can you help me ?
Thanks
Can the project be updated to support Es2020, or at least ES2015 so packaging of the code can take advantage of tree shaking.
You get warning like this atm
My tsconfig file looks like so
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"outDir": "../../out-tsc/app",
"types": [],
"module": "esnext",
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
My route tsconfig looks like so
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2020",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
}
}
Hello,
I want to ignore a holiday by using unsetRule
. The holiday does not appear in the list returned by getHolidays however when checking for that date using isHoliday I get the following Typerror
const hd = new Holidays();
hd.init('GR', { types: ['public'] });
hd.isHoliday('2023-04-14'); //returns true
hd.unsetRule('orthodox -2'); //returns true
hd.isHoliday('2023-04-14'); // => throws error
Uncaught TypeError: Cannot read property 'inYear' of undefined
at Holidays.isHoliday (node_modules/date-holidays-parser/lib/Holidays.cjs:220:33)
at Holidays._dateByRule (node_modules/date-holidays-parser/lib/Holidays.cjs:396:28)
I need to reduce the lib size (1.1MB) and I would like to know if there is a way to make it more lightweight ?
From this issue, I tried using date-holiday-parser (instead of date-holiday) with a custom json data but it made any improvement (still 1.1MB).
// date.utils.ts
import Holidays from 'date-holidays-parser';
const customHolidayJsonData = {
holidays: {
FR: {
names: {
fr: 'France',
en: 'France',
},
dayoff: 'sunday',
zones: ['Europe/Paris'],
langs: ['fr'],
days: {
'01-01': {
_name: '01-01',
},
},
},
},
names: {
'01-01': {
name: {
en: "New Year's Day",
fr: 'Nouvel An',
},
},
},
};
const holiday = new Holidays(customHolidayJsonData);
holiday.init('FR');
Is there a way of improvement / am I doing something wrong ?
Typescript definition: Holidays.isHoliday(date: Date): Holidays.Holiday
In reality it should be either Holidays.isHoliday(date: Date): Holidays.Holiday | boolean
or Holidays.isHoliday(date: Date): Holidays.Holiday | false
I'm getting 404 on the link to holiday data. Is there any existing database?
Hi.
First of all, thanks for this work, is amazing!
As part of discovering holidays data sources, I found this project. One of my uses cases would be to query all the holidays for a list of countries. Looking at the API docs, I found that the init method receives a Country instance. Is there a way to extend this to receive a list of countries? I guess one approach could be having a list of Holidays instances but a) Not sure how this would perform and 2) It would be cleaner to leave that to the module instead.
Any guidance on this would be appreciated.
Hi here,
I'm trying to use date-holidays in my angular 7 project with typescript.
I meet an issue when I intialize new Holidays('US', 'la', 'no') (for exemple) :
It seems that the problem occurs when the country is made of 2 characters, I have the same problem with new Holidays('Fr'), but when i'm doing new Holidays('France') the result is :
Beside, when I use something like
it works fine.
I think that there is something wrong with my init but i don't understand what.. I'm pretty new in the web development !
Thanks !
When trying to use this module with webpack and uglify it fails due to es6 features.
See webpack/webpack#5682 (comment)
Ideally there should be a prepublish script to compile the code to es5 so that it can be used with webpack without having to be specifically targeted for compilation.
I'd be happy to do up a PR for this if you want.
My company's business logic requires me to filter for only major holidays and a few local city holidays.
I've tried filtering the array from hd.getHolidays() and then setting the new filtered array of holidays but i'm still getting all of the holidays.
Is there a way to overwrite the current holiday array?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.