1-
21describe ( '$mdDateLocale' , function ( ) {
32 var dateLocale , dateUtil ;
43
@@ -81,7 +80,7 @@ describe('$mdDateLocale', function() {
8180
8281 describe ( 'with custom values' , function ( ) {
8382 var fakeMonths = [ 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L' ] ;
84- var fakeshortMonths = [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'j' , 'l' ] ;
83+ var fakeShortMonths = [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'j' , 'l' ] ;
8584 var fakeDays = [ 'D1' , 'D2' , 'D3' , 'D4' , 'D5' , 'D6' , 'D7' ] ;
8685 var fakeShortDays = [ '1' , '2' , '3' , '4' , '5' , '6' , '7' ] ;
8786 var fakeDates = [ undefined , 'X1' , 'X2' , 'X3' , 'X4' , 'X5' , 'X6' , 'X7' , 'X8' , 'X9' , 'X10' , 'X11' ,
@@ -90,7 +89,7 @@ describe('$mdDateLocale', function() {
9089
9190 beforeEach ( module ( function ( $mdDateLocaleProvider ) {
9291 $mdDateLocaleProvider . months = fakeMonths ;
93- $mdDateLocaleProvider . shortMonths = fakeshortMonths ;
92+ $mdDateLocaleProvider . shortMonths = fakeShortMonths ;
9493 $mdDateLocaleProvider . days = fakeDays ;
9594 $mdDateLocaleProvider . shortDays = fakeShortDays ;
9695 $mdDateLocaleProvider . dates = fakeDates ;
@@ -113,7 +112,7 @@ describe('$mdDateLocale', function() {
113112
114113 it ( 'should expose custom settings' , function ( ) {
115114 expect ( dateLocale . months ) . toEqual ( fakeMonths ) ;
116- expect ( dateLocale . shortMonths ) . toEqual ( fakeshortMonths ) ;
115+ expect ( dateLocale . shortMonths ) . toEqual ( fakeShortMonths ) ;
117116 expect ( dateLocale . days ) . toEqual ( fakeDays ) ;
118117 expect ( dateLocale . shortDays ) . toEqual ( fakeShortDays ) ;
119118 expect ( dateLocale . dates ) . toEqual ( fakeDates ) ;
@@ -124,4 +123,39 @@ describe('$mdDateLocale', function() {
124123 expect ( dateLocale . isDateComplete ( 'Anything Else' ) ) . toBe ( false ) ;
125124 } ) ;
126125 } ) ;
126+
127+ describe ( 'with MomentJS custom formatting' , function ( ) {
128+
129+ beforeEach ( module ( function ( $mdDateLocaleProvider ) {
130+ $mdDateLocaleProvider . formatDate = function ( date ) {
131+ return date ? moment ( date ) . format ( 'M/D' ) : '' ;
132+ } ;
133+ $mdDateLocaleProvider . parseDate = function ( dateString ) {
134+ var m = moment ( dateString , 'M/D' , true ) ;
135+ return m . isValid ( ) ? m . toDate ( ) : new Date ( NaN ) ;
136+ } ;
137+ $mdDateLocaleProvider . isDateComplete = function ( dateString ) {
138+ dateString = dateString . trim ( ) ;
139+ // Look for two chunks of content (either numbers or text) separated by delimiters.
140+ var re = / ^ ( ( [ a - z A - Z ] { 3 , } | [ 0 - 9 ] { 1 , 4 } ) ( [ . , ] + | [ / - ] ) ) ( [ a - z A - Z ] { 3 , } | [ 0 - 9 ] { 1 , 4 } ) / ;
141+ return re . test ( dateString ) ;
142+ } ;
143+ } ) ) ;
144+
145+ beforeEach ( inject ( function ( $mdDateLocale , $$mdDateUtil ) {
146+ dateLocale = $mdDateLocale ;
147+ dateUtil = $$mdDateUtil ;
148+ } ) ) ;
149+
150+ it ( 'should respect custom formatting' , function ( ) {
151+ var now = new Date ( ) ;
152+ expect ( dateLocale . formatDate ( new Date ( '2020-08-31T00:00:00-04:00' ) ) ) . toEqual ( '8/31' ) ;
153+ expect ( dateLocale . parseDate ( '8/31' ) ) . toEqual ( new Date ( now . getFullYear ( ) , 7 , 31 ) ) ;
154+ expect ( dateLocale . parseDate ( '1/1' ) ) . toEqual ( new Date ( now . getFullYear ( ) , 0 , 1 ) ) ;
155+ expect ( dateLocale . isDateComplete ( '8/31' ) ) . toBe ( true ) ;
156+ expect ( dateLocale . isDateComplete ( '8-31' ) ) . toBe ( true ) ;
157+ expect ( dateLocale . isDateComplete ( 'August_31st' ) ) . toBe ( false ) ;
158+ expect ( dateLocale . isDateComplete ( '2020' ) ) . toBe ( false ) ;
159+ } ) ;
160+ } ) ;
127161} ) ;
0 commit comments