mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 05:58:26 +08:00
fix(datetime-util): fix convertDataToISO to handle negative timezone offsets
This commit is contained in:

committed by
Adam Bradley

parent
44ab527f74
commit
ba53a23c6e
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user