Skip to content

Commit

Permalink
fix(datetime-util): fix convertDataToISO to handle negative timezone …
Browse files Browse the repository at this point in the history
…offsets
  • Loading branch information
hotforfeature authored and adamdbradley committed Jul 19, 2016
1 parent 44ab527 commit ba53a23
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/util/datetime-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
16 changes: 16 additions & 0 deletions src/util/test/datetime-util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ba53a23

Please sign in to comment.