Skip to content
This repository was archived by the owner on Mar 2, 2018. It is now read-only.

Commit 213f0b3

Browse files
committed
updated test app
1 parent 56f23e7 commit 213f0b3

File tree

1 file changed

+34
-59
lines changed

1 file changed

+34
-59
lines changed

app/directive-test.component.ts

Lines changed: 34 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Component, ViewEncapsulation } from '@angular/core';
22
import { Validators, FormGroup, FormArray, FormBuilder } from '@angular/forms';
33

4+
//noinspection TypeScriptCheckImport
5+
import { Ng2Datetime } from 'ng2-datetime-picker';
6+
47
declare var moment: any;
58
moment['locale']('en-ca'); //e.g. fr-ca
69

@@ -34,6 +37,31 @@ var templateStr = `
3437
<pre>{{templateStr | htmlCode:'ng2-utils-2'}}</pre>
3538
</fieldset>
3639
40+
<fieldset><legend><h2>time only</h2></legend>
41+
<ng2-utils-4>
42+
<input [(ngModel)]="date" ng2-datetime-picker
43+
id="test3"
44+
date-format="DD-MM-YYYY hh:mm"
45+
time-only="true"
46+
minute-step="5"
47+
close-on-select="false" />
48+
</ng2-utils-4>
49+
<pre>{{templateStr | htmlCode:'ng2-utils-4'}}</pre>
50+
</fieldset>
51+
52+
<fieldset><legend><h2>with timezone</h2></legend>
53+
<ng2-utils-6>
54+
<input
55+
id="test6"
56+
[(ngModel)]="dateWithTimezone"
57+
ng2-datetime-picker
58+
[date-format]="timezoneFormat" />
59+
dateWithTimezone: {{dateWithTimezone}}
60+
<br/>
61+
</ng2-utils-6>
62+
<pre>{{templateStr | htmlCode:'ng2-utils-6'}}</pre>
63+
</fieldset>
64+
3765
<fieldset><legend><h2>Reactive form</h2></legend>
3866
<ng2-utils-3>
3967
<form [formGroup]="myForm">
@@ -65,62 +93,6 @@ var templateStr = `
6593
<pre>{{templateStr | htmlCode:'ng2-utils-3'}}</pre>
6694
</fieldset>
6795
68-
<fieldset><legend><h2>time only</h2></legend>
69-
<ng2-utils-4>
70-
<input [(ngModel)]="date" ng2-datetime-picker
71-
id="test3"
72-
date-format="DD-MM-YYYY hh:mm"
73-
time-only="true"
74-
minute-step="5"
75-
close-on-select="false" />
76-
</ng2-utils-4>
77-
<pre>{{templateStr | htmlCode:'ng2-utils-4'}}</pre>
78-
</fieldset>
79-
80-
<fieldset><legend><h2>GMT date as string</h2></legend>
81-
<ng2-utils-5>
82-
<input
83-
id="test4"
84-
[(ngModel)]="gmtDate"
85-
ng2-datetime-picker
86-
date-format="MM-DD-YYYY" />
87-
gmtDate : "2015-01-01T00:00:00.000Z"
88-
<br/>
89-
<a href="javascript:void()"
90-
(click)="gmtDate='2016-11-03T22:00:00Z'">
91-
Set date/time to: 2016-11-03T22:00:00Z
92-
</a>
93-
</ng2-utils-5>
94-
<pre>{{templateStr | htmlCode:'ng2-utils-5'}}</pre>
95-
</fieldset>
96-
97-
<fieldset><legend><h2>with timezone</h2></legend>
98-
<ng2-utils-6>
99-
<input
100-
id="test6"
101-
[(ngModel)]="dateWithTimezoneInfo"
102-
ng2-datetime-picker
103-
date-format="YYYY-MM-DD HH:mm Z" />
104-
dateWithTimezoneInfo: {{dateWithTimezoneInfo}}
105-
<br/>
106-
</ng2-utils-6>
107-
<pre>{{templateStr | htmlCode:'ng2-utils-6'}}</pre>
108-
</fieldset>
109-
110-
<fieldset><legend><h2>parse-format</h2></legend>
111-
<ng2-utils-7>
112-
<input
113-
id="test7"
114-
[(ngModel)]="dateWithTime"
115-
ng2-datetime-picker
116-
date-format="MM/DD/YYYY HH:mm z"
117-
parse-format="YYYY-MM-DDTHH:mm:ss"/>
118-
dateWithTime: {{dateWithTime}}
119-
<br/>
120-
</ng2-utils-7>
121-
<pre>{{templateStr | htmlCode:'ng2-utils-7'}}</pre>
122-
</fieldset>
123-
12496
</div>
12597
`;
12698

@@ -141,13 +113,12 @@ export class DirectiveTestComponent {
141113

142114
myForm: FormGroup; // our form model
143115
date = new Date("Thu Jan 01 2015 00:00:00 GMT-0500 (EST)");
144-
gmtDate = '2015-01-01T00:00:00.000Z';
145-
dateWithTimezoneInfo = '2017-01-15T14:22:00-06:00';
146116
defaultValue = new Date(2014, 11, 31, 21, 45, 59);
147117
minDate = new Date(2017, 0, 1);
148118
maxDate = new Date(2017, 11, 31);
149119
disabledDates = [new Date(2016, 11, 26), new Date(2016, 11, 27)];
150-
dateWithTime = '2017-1-15T14:22:00-05:00';
120+
dateWithTimezone: string;
121+
timezoneFormat = 'DD/MM/YYYY HH:mm Z';
151122

152123
constructor(private fb: FormBuilder) { }
153124

@@ -157,6 +128,10 @@ export class DirectiveTestComponent {
157128
});
158129

159130
moment.tz.setDefault('US/Central'); // Set the default timezone that moment will use
131+
132+
this.dateWithTimezone = Ng2Datetime.formatDate(
133+
Ng2Datetime.parseDate('2017-01-15T14:22:00-06:00', this.timezoneFormat), this.timezoneFormat
134+
);
160135
}
161136

162137
}

0 commit comments

Comments
 (0)