Skip to content

Commit

Permalink
fix(datetime): fix ISO format when w/out timezone data
Browse files Browse the repository at this point in the history
Closes #6608
  • Loading branch information
adamdbradley committed Jun 1, 2016
1 parent c1ad804 commit 272daf2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/components/datetime/test/basic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class E2EPage {
webkitOpenSourced = '2005-06-17T11:06Z';
chromeReleased = '2008-09-02';
leapYearsSummerMonths = '';
convertedDate = '';

leapYearsArray = [2020, 2016, 2008, 2004, 2000, 1996];

Expand All @@ -39,6 +40,10 @@ class E2EPage {
this.leapYearsSummerMonths = null;
}

convertDate() {
this.convertedDate = new Date(this.myDate).toISOString();
}

}


Expand Down
14 changes: 13 additions & 1 deletion src/components/datetime/test/basic/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@
<code>Leap year, summer months: {{leapYearsSummerMonths}}</code><br>
</p>

<button (click)="clearLeapYear()">Clear Leap Years</button>
<p>
<button (click)="clearLeapYear()">Clear Leap Years</button>
</p>

<ion-item>
<ion-label>myDate: {{myDate}}</ion-label>
<ion-datetime displayFormat="MMM DD, YYYY HH:mm" [(ngModel)]="myDate"></ion-datetime>
</ion-item>

<p>
<button (click)="convertDate()">Convert myDate To Date</button>
{{convertedDate}}
</p>

</ion-content>
2 changes: 1 addition & 1 deletion src/util/datetime-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export function convertDataToISO(data: DateTimeData): string {
rtn += '.' + threeDigit(data.millisecond);
}

if (data.tzOffset === 0) {
if (isBlank(data.tzOffset) || data.tzOffset === 0) {
// YYYY-MM-DDTHH:mm:SSZ
rtn += 'Z';

Expand Down
14 changes: 14 additions & 0 deletions src/util/test/datetime-util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ export function run() {

describe('convertDataToISO', () => {

it('should convert DateTimeData to datetime string, with blank timezone', () => {
var data: datetime.DateTimeData = {
year: 1994,
month: 12,
day: 15,
hour: 13,
minute: 47,
second: 20,
};

var str = datetime.convertDataToISO(data);
expect(str).toEqual('1994-12-15T13:47:20Z');
});

it('should convert DateTimeData to datetime string, +330 tz offset', () => {
var data: datetime.DateTimeData = {
year: 1994,
Expand Down

0 comments on commit 272daf2

Please sign in to comment.