From 1cb57d9725837274acbfc3cf42a752e71fb61e39 Mon Sep 17 00:00:00 2001 From: Toshihiro Sugimoto Date: Fri, 4 Apr 2025 18:29:21 +0900 Subject: [PATCH] fix: Error when trying to change AM/PM before selecting a time --- src/js/actions.ts | 2 +- test/actions.test.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/js/actions.ts b/src/js/actions.ts index 11705dbdc..0ece97c1e 100644 --- a/src/js/actions.ts +++ b/src/js/actions.ts @@ -113,7 +113,7 @@ export default class Actions { this.manipulateAndSet( lastPicked, Unit.hours, - this.dates.lastPicked.hours >= 12 ? -12 : 12 + lastPicked.hours >= 12 ? -12 : 12 ); break; case ActionTypes.togglePicker: diff --git a/test/actions.test.ts b/test/actions.test.ts index 61625bc37..157eddbca 100644 --- a/test/actions.test.ts +++ b/test/actions.test.ts @@ -410,6 +410,14 @@ test('toggleMeridiem', () => { expect(dates.picked).toEqual([shouldBe.manipulate(12, Unit.hours)]); expect(hideSpy).not.toHaveBeenCalled(); expect(isValidSpy).toHaveBeenCalled(); + + //before selecting a time + dates.clear(); + actions.do(event, ActionTypes.toggleMeridiem); + expect(setValueSpy).toHaveBeenCalled(); + expect(dates.picked).toEqual([shouldBe.manipulate(-12, Unit.hours)]); + expect(hideSpy).not.toHaveBeenCalled(); + expect(isValidSpy).toHaveBeenCalled(); }); test('togglePicker', () => {