From 4e01be424556dea0499c2c4386de9783ef8213b0 Mon Sep 17 00:00:00 2001 From: Rohland de Charmoy Date: Mon, 27 Nov 2023 10:08:52 +0200 Subject: [PATCH] :bug: fixed bug with dates and mute windows --- package.json | 2 +- src/lib/utility.ts | 4 ++-- src/models/mute-window.spec.ts | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 76dc451..64d2042 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "barky", - "version": "1.1.5", + "version": "1.1.6", "description": "A simple cloud services watchdog with digest notification support & no external dependencies", "homepage": "https://github.com/Rohland/barky#readme", "main": "dist/cli.js", diff --git a/src/lib/utility.ts b/src/lib/utility.ts index 624688d..0f23e5e 100644 --- a/src/lib/utility.ts +++ b/src/lib/utility.ts @@ -61,8 +61,8 @@ export function isToday(date: string, on?: Date): boolean { return inputDate.getTime() === today.getTime(); } -export function dayOfWeek(date: Date): number { - const day = date.toLocaleString("en-US", { +export function dayOfWeek(date?: Date): number { + const day = (date || new Date()).toLocaleString("en-US", { timeZone: timeZone, weekday: 'short' }); diff --git a/src/models/mute-window.spec.ts b/src/models/mute-window.spec.ts index 30717a8..71903a1 100644 --- a/src/models/mute-window.spec.ts +++ b/src/models/mute-window.spec.ts @@ -93,6 +93,22 @@ describe("mute-windows", () => { }); }); }); + describe("can be called with null date", () => { + it("should infer now", async () => { + // arrange + const config = { + time: "00:00-24:00", + date: new Date().toISOString().split('T')[0], + days: ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] }; + const muteWindow = new MuteWindow(config); + + // act + const isMuted = muteWindow.isMutedAt(); + + // assert + expect(isMuted).toEqual(true); + }); + }); }); describe("with match", () => { describe.each([