11
11
< link rel ="stylesheet " href ="https://rawgit.com/eight04/end2end/master/dist/end2end.css ">
12
12
13
13
< script >
14
- function shallow ( o ) {
15
- var o2 = { } , key ;
16
- for ( key in o ) {
17
- o2 [ key ] = o [ key ] ;
18
- }
19
- return o2 ;
20
- }
21
14
angular . module ( "App" , [ "datetime" ] ) . controller ( "myDate" , function ( $scope , datetime , $locale ) {
22
- $scope . myDate = {
23
- demo : new Date ,
24
- date : new Date ,
25
- required : new Date ,
26
- other : new Date ,
27
- min : new Date ( 2010 , 0 , 1 ) ,
28
- max : new Date ( 2019 , 11 , 31 ) ,
29
- model : "2000-01-01 00:00:00"
30
- } ;
15
+
16
+ $scope . myDate = new Date ;
17
+ $scope . myDateString = "2000-01-01 00:00:00" ;
18
+ $scope . min = new Date ( 2010 , 0 , 1 ) ;
19
+ $scope . max = new Date ( 2019 , 11 , 31 ) ;
20
+
31
21
$scope . formats = function ( formats ) {
32
22
var swap = [ ] , format , code ;
33
23
for ( format in formats ) {
38
28
}
39
29
return swap ;
40
30
} ( $locale . DATETIME_FORMATS ) ;
31
+
41
32
$scope . reset = function ( ) {
42
- $scope . myDate . demo = new Date ;
43
- $scope . myDate . date = new Date ;
44
- $scope . myDate . required = new Date ;
45
- $scope . myDate . other = new Date ;
46
- $scope . myDate . model = "2000-01-01 00:00:00" ;
33
+ $scope . myDate = new Date ;
34
+ $scope . myDateString = "2000-01-01 00:00:00" ;
47
35
}
36
+
48
37
$scope . clear = function ( ) {
49
- $scope . myDate . demo = null ;
50
- $scope . myDate . date = null ;
51
- $scope . myDate . required = null ;
52
- $scope . myDate . other = null ;
53
- $scope . myDate . model = null ;
38
+ $scope . myDate = null ;
39
+ $scope . myDateString = null ;
54
40
}
55
-
56
- var parser = datetime ( "Z" ) ;
57
- console . log ( parser . getText ( ) ) ;
58
41
} ) ;
59
42
</ script >
60
43
@@ -69,45 +52,50 @@ <h2>Angular Datetime <small>Demo Page</small></h2>
69
52
< button class ="btn-default " ng-click ="clear() "> Clear</ button >
70
53
</ p >
71
54
< p > To use the directive, add < code > datetime="date-format"</ code > attribute to your input.</ p >
72
- < input type ="text " datetime ="yyyy-MM-dd HH:mm:ss " ng-model ="myDate.demo " class ="form-control ">
55
+ < input type ="text " datetime ="yyyy-MM-dd HH:mm:ss " ng-model ="myDate " class ="form-control ">
73
56
< pre class ="code "> < code > <input type="text" datetime="yyyy-MM-dd HH:mm:ss" ng-model="myDate"></ code > </ pre >
74
57
75
58
< h3 > Min / Max</ h3 >
76
59
< p > Validation for min/max date. The min/max attribute will be used to construct the date object.</ p >
77
- < input type ="text " datetime ="yyyy-MM-dd HH:mm:ss " ng-model ="myDate.demo " class ="form-control " min ="{{myDate. min.toISOString()}} " max ="{{myDate. max.toISOString()}} ">
60
+ < input type ="text " datetime ="yyyy-MM-dd HH:mm:ss " ng-model ="myDate " class ="form-control " min ="{{min.toISOString()}} " max ="{{max.toISOString()}} ">
78
61
< pre class ="code " ng-non-bindable > < code > <input type="text" datetime="yyyy-MM-dd HH:mm:ss" ng-model="myDate" min="Jan 1, 2010" max="Dec 31, 2019"></ code > </ pre >
79
62
80
63
< div class ="form-group ">
81
64
< label >
82
65
Min
83
- < input type ="text " datetime ="yyyy-MM-dd HH:mm:ss " ng-model ="myDate. min " class ="form-control ">
66
+ < input type ="text " datetime ="yyyy-MM-dd HH:mm:ss " ng-model ="min " class ="form-control ">
84
67
</ label >
85
68
</ div >
86
69
87
70
< div class ="form-group ">
88
71
< label >
89
72
Max
90
- < input type ="text " datetime ="yyyy-MM-dd HH:mm:ss " ng-model ="myDate. max " class ="form-control ">
73
+ < input type ="text " datetime ="yyyy-MM-dd HH:mm:ss " ng-model ="max " class ="form-control ">
91
74
</ label >
92
75
</ div >
93
76
94
77
< h3 > Required</ h3 >
95
78
< p > You won't be able to clear this field if required. You can still set the model value to null though.</ p >
96
- < input type ="text " datetime ="yyyy-MM-dd HH:mm:ss " ng-model ="myDate.demo " class ="form-control " required >
79
+ < input type ="text " datetime ="yyyy-MM-dd HH:mm:ss " ng-model ="myDate " class ="form-control " required >
97
80
< pre class ="code "> < code > <input type="text" datetime="yyyy-MM-dd HH:mm:ss" ng-model="myDate" required></ code > </ pre >
98
81
99
82
< h3 > Model format</ h3 >
100
83
< p > You can use a date string instead of date object as model value.</ p >
101
84
< input type ="text " class ="form-control " datetime ="medium " ng-model ="myDate.model " datetime-model ="yyyy-MM-dd HH:mm:ss ">
102
- < pre class ="output "> myDate = {{myDate.model | json}}</ pre >
103
- < pre class ="code "> < code > <input type="text" datetime="medium" datetime-model="yyyy-MM-dd HH:mm:ss" ng-model="myDate"></ code > </ pre >
85
+ < pre class ="output "> myDate = {{myDateString | json}}</ pre >
86
+ < pre class ="code "> < code > <input type="text" datetime="medium" datetime-model="yyyy-MM-dd HH:mm:ss" ng-model="myDateString"></ code > </ pre >
87
+
88
+ < h3 > Show UTC</ h3 >
89
+ < p > By the default, angular-datetime will format view value in local timezone. Add < code > use-utc</ code > attribute to show UTC time to users.</ p >
90
+ < input type ="text " datetime ="yyyy-MM-dd HH:mm:ss " ng-model ="myDate " class ="form-control " use-utc >
91
+ < pre class ="code "> < code > <input type="text" datetime="yyyy-MM-dd HH:mm:ss" ng-model="myDate" use-utc></ code > </ pre >
104
92
105
93
< h3 > Localizable formats</ h3 >
106
94
< p > The parser supports localizable formats in angular.</ p >
107
95
< div class ="form-group " ng-repeat ="format in formats ">
108
96
< label >
109
97
{{format}}
110
- < input type ="text " datetime ="{{format}} " class ="form-control " ng-model ="myDate.date ">
98
+ < input type ="text " datetime ="{{format}} " class ="form-control " ng-model ="myDate ">
111
99
</ label >
112
100
</ div >
113
101
0 commit comments