fix(datetime-util): fix convertDataToISO to handle negative timezone offsets

This commit is contained in:
Andrew Mitchell
2016-07-19 15:35:36 -05:00
committed by Adam Bradley
parent 44ab527f74
commit ba53a23c6e
2 changed files with 19 additions and 3 deletions

View File

@ -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);
}

View File

@ -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,