From ba53a23c6e9486f4a00444799a64330a79bfa766 Mon Sep 17 00:00:00 2001 From: Andrew Mitchell Date: Tue, 19 Jul 2016 15:35:36 -0500 Subject: [PATCH] fix(datetime-util): fix convertDataToISO to handle negative timezone offsets --- src/util/datetime-util.ts | 6 +++--- src/util/test/datetime-util.spec.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/util/datetime-util.ts b/src/util/datetime-util.ts index fce66de3161..a90a5fa966e 100644 --- a/src/util/datetime-util.ts +++ b/src/util/datetime-util.ts @@ -390,15 +390,15 @@ export function convertDataToISO(data: DateTimeData): string { } function twoDigit(val: number): string { - return ('0' + (isPresent(val) ? val : '0')).slice(-2); + return ('0' + (isPresent(val) ? Math.abs(val) : '0')).slice(-2); } function threeDigit(val: number): string { - return ('00' + (isPresent(val) ? val : '0')).slice(-3); + return ('00' + (isPresent(val) ? Math.abs(val) : '0')).slice(-3); } function fourDigit(val: number): string { - return ('000' + (isPresent(val) ? val : '0')).slice(-4); + return ('000' + (isPresent(val) ? Math.abs(val) : '0')).slice(-4); } diff --git a/src/util/test/datetime-util.spec.ts b/src/util/test/datetime-util.spec.ts index 6ca8c850080..16328af78a7 100644 --- a/src/util/test/datetime-util.spec.ts +++ b/src/util/test/datetime-util.spec.ts @@ -34,6 +34,22 @@ describe('convertDataToISO', () => { expect(str).toEqual('1994-12-15T13:47:20.789+05:30'); }); + it('should convert DateTimeData to datetime string, -300 tz offset', () => { + var data: datetime.DateTimeData = { + year: 1994, + month: 12, + day: 15, + hour: 13, + minute: 47, + second: 20, + millisecond: 789, + tzOffset: -300, + }; + + var str = datetime.convertDataToISO(data); + expect(str).toEqual('1994-12-15T13:47:20.789-05:00'); + }); + it('should convert DateTimeData to datetime string, Z timezone', () => { var data: datetime.DateTimeData = { year: 1994,