Browse Source

Merge 3a3110457f into d58122f957

pull/7491/merge
CoderVJain 1 hour ago
committed by GitHub
parent
commit
77486e8c06
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 28
      libs/common/src/lib/helper.ahead-of-utc.time-zone.spec.ts
  3. 28
      libs/common/src/lib/helper.behind-utc.time-zone.spec.ts
  4. 8
      libs/common/src/lib/helper.ts
  5. 36
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.spec.ts
  6. 7
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts
  7. 7
      libs/ui/src/lib/services/data.service.ts

1
CHANGELOG.md

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Fixed the date shift of the market data in the portfolio calculation in time zones behind UTC - Fixed the date shift of the market data in the portfolio calculation in time zones behind UTC
- Fixed the date shift of the historical market data in the asset profile dialog and the holding detail dialog for users in a time zone behind UTC
- Fixed the dates of manually entered historical market data in time zones other than UTC - Fixed the dates of manually entered historical market data in time zones other than UTC
## 3.101.0 - 2026-11-28 ## 3.101.0 - 2026-11-28

28
libs/common/src/lib/helper.ahead-of-utc.time-zone.spec.ts

@ -0,0 +1,28 @@
/**
* @jest-environment <rootDir>/../../apps/api/jest-environment-tz.js
* @jest-environment-options {"timeZone": "Pacific/Auckland"}
*/
import {
DATE_FORMAT,
getLocalDateFromUtcDate
} from '@ghostfolio/common/helper';
import { format } from 'date-fns';
describe('Helper in a time zone ahead of UTC', () => {
describe('Get local date from UTC date', () => {
it.each([
['in summer time', '2026-01-01', '2025-12-31T11:00:00.000Z'],
['at the end of summer time', '2026-04-05', '2026-04-04T11:00:00.000Z'],
['in standard time', '2026-07-01', '2026-06-30T12:00:00.000Z'],
['at the start of summer time', '2026-09-27', '2026-09-26T12:00:00.000Z']
])('Preserve the calendar date %s', (_, dateString, localMidnight) => {
const localDate = getLocalDateFromUtcDate(
new Date(`${dateString}T00:00:00.000Z`)
);
expect(format(localDate, DATE_FORMAT)).toEqual(dateString);
expect(localDate).toEqual(new Date(localMidnight));
});
});
});

28
libs/common/src/lib/helper.behind-utc.time-zone.spec.ts

@ -0,0 +1,28 @@
/**
* @jest-environment <rootDir>/../../apps/api/jest-environment-tz.js
* @jest-environment-options {"timeZone": "America/New_York"}
*/
import {
DATE_FORMAT,
getLocalDateFromUtcDate
} from '@ghostfolio/common/helper';
import { format } from 'date-fns';
describe('Helper in a time zone behind UTC', () => {
describe('Get local date from UTC date', () => {
it.each([
['in standard time', '2026-01-01', '2026-01-01T05:00:00.000Z'],
['at the start of summer time', '2026-03-08', '2026-03-08T05:00:00.000Z'],
['in summer time', '2026-07-01', '2026-07-01T04:00:00.000Z'],
['at the end of summer time', '2026-11-01', '2026-11-01T04:00:00.000Z']
])('Preserve the calendar date %s', (_, dateString, localMidnight) => {
const localDate = getLocalDateFromUtcDate(
new Date(`${dateString}T00:00:00.000Z`)
);
expect(format(localDate, DATE_FORMAT)).toEqual(dateString);
expect(localDate).toEqual(new Date(localMidnight));
});
});
});

8
libs/common/src/lib/helper.ts

@ -493,6 +493,14 @@ export function getHoldingName({
return name ?? symbol; return name ?? symbol;
} }
export function getLocalDateFromUtcDate(aUtcDate: Date) {
return new Date(
aUtcDate.getUTCFullYear(),
aUtcDate.getUTCMonth(),
aUtcDate.getUTCDate()
);
}
export function getLocale() { export function getLocale() {
return navigator.language ?? DEFAULT_LOCALE; return navigator.language ?? DEFAULT_LOCALE;
} }

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

@ -57,4 +57,40 @@ describe('GfHistoricalMarketDataEditorComponent', () => {
expect(component.formatDay(31)).toBe('31'); expect(component.formatDay(31)).toBe('31');
}); });
}); });
describe('ngOnChanges', () => {
afterEach(() => {
jest.useRealTimers();
});
it('should keep the market price of today if the last item is in the future', () => {
jest.useFakeTimers().setSystemTime(new Date(2026, 10, 29, 20));
fixture.componentRef.setInput('marketData', [
{ date: new Date(2026, 10, 29), marketPrice: 1 },
{ date: new Date(2026, 10, 30), marketPrice: 2 }
]);
fixture.detectChanges();
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();
});
});
}); });

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

@ -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 || !isToday(lastDate)) { return isToday(date);
});
if (!hasMarketDataOfToday) {
marketDataItems.push({ date: new Date() }); marketDataItems.push({ date: new Date() });
} }

7
libs/ui/src/lib/services/data.service.ts

@ -19,7 +19,10 @@ import {
UpdateTagDto, UpdateTagDto,
UpdateUserSettingDto UpdateUserSettingDto
} from '@ghostfolio/common/dtos'; } from '@ghostfolio/common/dtos';
import { DATE_FORMAT } from '@ghostfolio/common/helper'; import {
DATE_FORMAT,
getLocalDateFromUtcDate
} from '@ghostfolio/common/helper';
import { import {
AccessResponse, AccessResponse,
AccessTokenResponse, AccessTokenResponse,
@ -593,7 +596,7 @@ export class DataService {
.pipe( .pipe(
map((data) => { map((data) => {
for (const item of data.marketData) { for (const item of data.marketData) {
item.date = parseISO(item.date); item.date = getLocalDateFromUtcDate(parseISO(item.date));
} }
for (const item of data.splits ?? []) { for (const item of data.splits ?? []) {

Loading…
Cancel
Save