Skip to content
This repository was archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #43 from keithpops/patch-1
Browse files Browse the repository at this point in the history
Fixes invalid dates being returned from holiday list
  • Loading branch information
mgwalker authored Apr 5, 2023
2 parents c7563ea + 8bd0f3e commit b61d5e3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: tests

on: [push]
on: [pull_request, push]

jobs:
test:
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const utcPlugin = require("dayjs/plugin/utc");
dayjs.extend(utcPlugin);

const getDateFor = ({ day = 1, month, year }) =>
dayjs(`${year}-${month}-${day}`, "YYYY-MM-DD");
dayjs(`${year}-${month}-${day}`, "YYYY-M-D");

const getNthDayOf = (n, day, month, year) => {
let result = dayjs(getDateFor({ month, year })).day(day);
Expand All @@ -27,7 +27,7 @@ const getNthDayOf = (n, day, month, year) => {

const getLastDayOf = (day, month, year) => {
const daysInMonth = dayjs(getDateFor({ month, year })).daysInMonth();
const lastDayOfMonth = dayjs(`${year}-${month}-${daysInMonth}`, "YYYY-MM-DD");
const lastDayOfMonth = dayjs(`${year}-${month}-${daysInMonth}`, "YYYY-M-D");

let result = lastDayOfMonth.day(day);

Expand Down
9 changes: 9 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const customParseFormat = require("dayjs/plugin/customParseFormat");
const dayjs = require("dayjs");
const tap = require("tap");

// The customParseFormat plugin changes the way the dayjs() utility method
// handles format strings. Specifically, MM and DD format tokens will REQUIRE
// two-digit months and days, whereas the default constructor will happily take
// single-digit months and days. Add the plugin to our tests to make sure we
// still work in environments where the plugin is being used.
dayjs.extend(customParseFormat);

const federalHolidays = require("./index");

const getDate = dateString => new Date(`${dateString} 00:00:00`);
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@18f/us-federal-holidays",
"version": "3.0.1",
"version": "3.0.2",
"description": "All about US federal holidays",
"main": "index.js",
"keywords": [
Expand All @@ -17,7 +17,8 @@
"Alexandr Rodik (https://github.com/arodik)",
"Ian Speers (https://github.com/ian-speers)",
"Tse Kit Yam (https://github.com/tsekityam)",
"Ben Berry (https://github.com/bengerman13)"
"Ben Berry (https://github.com/bengerman13)",
"Keith Pops (https://github.com/keithpops)"
],
"repository": {
"type": "git",
Expand Down

0 comments on commit b61d5e3

Please sign in to comment.