Browse Source

Fix missing today in historical market data editor

pull/7491/head
Thomas Kaul 14 hours ago
parent
commit
3a3110457f
  1. 17
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.spec.ts
  2. 11
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts

17
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); 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();
});
}); });
}); });

11
libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts

@ -37,11 +37,11 @@ import {
format, format,
isBefore, isBefore,
isSameDay, isSameDay,
isToday,
isValid, isValid,
min, min,
parse, parse,
parseISO, parseISO
startOfToday
} from 'date-fns'; } from 'date-fns';
import ms from 'ms'; import ms from 'ms';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
@ -152,8 +152,11 @@ export class GfHistoricalMarketDataEditorComponent
const marketDataItems = [...missingMarketData, ...this.marketData()]; const marketDataItems = [...missingMarketData, ...this.marketData()];
const lastDate = marketDataItems.at(-1)?.date; const hasMarketDataOfToday = marketDataItems.some(({ date }) => {
if (!lastDate || isBefore(lastDate, startOfToday())) { return isToday(date);
});
if (!hasMarketDataOfToday) {
marketDataItems.push({ date: new Date() }); marketDataItems.push({ date: new Date() });
} }

Loading…
Cancel
Save