Skip to content

Commit ba53a23

Browse files
hotforfeatureadamdbradley
authored andcommitted
fix(datetime-util): fix convertDataToISO to handle negative timezone offsets
1 parent 44ab527 commit ba53a23

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/util/datetime-util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,15 @@ export function convertDataToISO(data: DateTimeData): string {
390390
}
391391

392392
function twoDigit(val: number): string {
393-
return ('0' + (isPresent(val) ? val : '0')).slice(-2);
393+
return ('0' + (isPresent(val) ? Math.abs(val) : '0')).slice(-2);
394394
}
395395

396396
function threeDigit(val: number): string {
397-
return ('00' + (isPresent(val) ? val : '0')).slice(-3);
397+
return ('00' + (isPresent(val) ? Math.abs(val) : '0')).slice(-3);
398398
}
399399

400400
function fourDigit(val: number): string {
401-
return ('000' + (isPresent(val) ? val : '0')).slice(-4);
401+
return ('000' + (isPresent(val) ? Math.abs(val) : '0')).slice(-4);
402402
}
403403

404404

src/util/test/datetime-util.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ describe('convertDataToISO', () => {
3434
expect(str).toEqual('1994-12-15T13:47:20.789+05:30');
3535
});
3636

37+
it('should convert DateTimeData to datetime string, -300 tz offset', () => {
38+
var data: datetime.DateTimeData = {
39+
year: 1994,
40+
month: 12,
41+
day: 15,
42+
hour: 13,
43+
minute: 47,
44+
second: 20,
45+
millisecond: 789,
46+
tzOffset: -300,
47+
};
48+
49+
var str = datetime.convertDataToISO(data);
50+
expect(str).toEqual('1994-12-15T13:47:20.789-05:00');
51+
});
52+
3753
it('should convert DateTimeData to datetime string, Z timezone', () => {
3854
var data: datetime.DateTimeData = {
3955
year: 1994,

0 commit comments

Comments
 (0)