From 3a3110457fc380be2fc8c142d5c688fa415d699c Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 29 Nov 2026 10:17:22 +0100 Subject: [PATCH] Fix missing today in historical market data editor --- ...torical-market-data-editor.component.spec.ts | 17 +++++++++++++++++ .../historical-market-data-editor.component.ts | 11 +++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.spec.ts b/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.spec.ts index e3526df8f5..d22634c9ab 100644 --- a/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.spec.ts +++ b/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.spec.ts @@ -75,5 +75,22 @@ describe('GfHistoricalMarketDataEditorComponent', () => { expect(component.marketDataByMonth['2026-11']['29'].marketPrice).toBe(1); }); + + it('should include today if all items are in the future', () => { + jest.useFakeTimers().setSystemTime(new Date(2026, 10, 29, 20)); + + fixture.componentRef.setInput('marketData', [ + { date: new Date(2027, 0, 15), marketPrice: 1 } + ]); + + fixture.detectChanges(); + + expect(Object.keys(component.marketDataByMonth).sort()).toEqual([ + '2026-11', + '2026-12', + '2027-01' + ]); + expect(component.marketDataByMonth['2026-11']['29']).toBeDefined(); + }); }); }); diff --git a/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts b/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts index 8d8aee1a93..bf5d20166b 100644 --- a/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts +++ b/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts @@ -37,11 +37,11 @@ import { format, isBefore, isSameDay, + isToday, isValid, min, parse, - parseISO, - startOfToday + parseISO } from 'date-fns'; import ms from 'ms'; import { DeviceDetectorService } from 'ngx-device-detector'; @@ -152,8 +152,11 @@ export class GfHistoricalMarketDataEditorComponent const marketDataItems = [...missingMarketData, ...this.marketData()]; - const lastDate = marketDataItems.at(-1)?.date; - if (!lastDate || isBefore(lastDate, startOfToday())) { + const hasMarketDataOfToday = marketDataItems.some(({ date }) => { + return isToday(date); + }); + + if (!hasMarketDataOfToday) { marketDataItems.push({ date: new Date() }); }