Skip to content

Commit

Permalink
Added Z to convertDoyToYmd to stop local timezone conversion (#1094)
Browse files Browse the repository at this point in the history
* Added Z to convertDoyToYmd to stop local timezone conversion

* Converted to template string
  • Loading branch information
cohansen authored and JosephVolosin committed Oct 21, 2024
1 parent 3592125 commit d82bd03
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/utilities/time.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ test('convertUsToDurationString', () => {
});

test('convertDoyToYmd', () => {
expect(convertDoyToYmd('2023-001T00:10:12', false)).toEqual('2023-01-01T00:10:12');
expect(convertDoyToYmd('2023-001T00:00:00', false)).toEqual('2023-01-01T00:00:00');
expect(convertDoyToYmd('2023-032T00:00:00', false)).toEqual('2023-02-01T00:00:00');
expect(convertDoyToYmd('2023-048T10:32:44.123', true)).toEqual('2023-02-17T10:32:44.123');
expect(convertDoyToYmd('2023-001T00:10:12', false)).toEqual('2023-01-01T00:10:12Z');
expect(convertDoyToYmd('2023-001T00:00:00', false)).toEqual('2023-01-01T00:00:00Z');
expect(convertDoyToYmd('2023-032T00:00:00', false)).toEqual('2023-02-01T00:00:00Z');
expect(convertDoyToYmd('2023-048T10:32:44.123', true)).toEqual('2023-02-17T10:32:44.123Z');
});

test('getDaysInMonth', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export function convertDoyToYmd(doyString: string, includeMsecs = true): string
padStart(`${date.getUTCDate()}`, 2, '0'),
].join('-')}T${parsedDoy.time}`;
if (includeMsecs) {
return ymdString;
return `${ymdString}Z`;
}
return ymdString.replace(/(\.\d+)/, '');
return `${ymdString.replace(/(\.\d+)/, '')}Z`;
} else {
// doyString is already in ymd format
return doyString;
Expand Down

0 comments on commit d82bd03

Please sign in to comment.