Giter Site home page Giter Site logo

date-holidays-parser's Issues

Problem with date in different timezone (UTC Offset)

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.:

  • checking if 01-01-2018 is a holiday
  • in australia timezone this day is 2017-12-31T13:00:00.000Z
  • when using hd.isHoliday it uses const year = toYear(date); which returns 2017
  • thus, it gets the holidays set from 2017 which ends up in not being a holiday, once there is no data where the given date is => startDate or < endDate (according from the excerpt of the code)
if (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.

parsing PT12H truncates end at midnight - is this desired behaviour?

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?

I am getting both the holiday AND the substitute day

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

Proposal: New rule for attribution of active/ inactive holidays

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

o.str.substr is not a function

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 functions!!

Please fix, this is very annoying as this completely breaks the whole library for me 😢

Weekday spelling in rules is in lowercase only

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 new rule "<date> on weekday"

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.

Export typescript definitions

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.

set Day Off

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

Including in Angular causing commonjs warnings

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

image

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"
    ]
  }
}

Must use import to load ES Module

Hello,

I'm using date-holidays in a Vtex.IO project.

Here I can only use import and not require.

However, I am getting this error when trying to use the lib.

Captura de Tela 2021-08-11 às 11 57 13

Any way to solve?

TypeError After UnsetRule

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)

How to make the lib more lightweight ?

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 ?

Capture d’écran 2022-09-22 à 10 18 02

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 ?

Data?

I'm getting 404 on the link to holiday data. Is there any existing database?

Get holidays for a subset (or all) the available countries

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.

Error: this._shorten is not a function

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) :

image

image

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 :

image

Beside, when I use something like
image
it works fine.

My import is made as follow:
image

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 !

Compile to es5 for the published version

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.

Custom holiday list

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.