File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -333,7 +333,12 @@ SELF.getPrecisionById = function( id ) {
333
333
* @return {string }
334
334
*/
335
335
function pad ( number , digits ) {
336
- return ( ( 1e12 + Math . abs ( number ) ) . toString ( ) ) . slice ( - digits ) ;
336
+ number = String ( Math . abs ( number ) ) ;
337
+ if ( number . length >= digits ) {
338
+ return number ;
339
+ }
340
+
341
+ return new Array ( digits - number . length + 1 ) . join ( '0' ) + number ;
337
342
}
338
343
339
344
dv . registerDataValue ( SELF ) ;
Original file line number Diff line number Diff line change @@ -60,6 +60,35 @@ define( [
60
60
! timeValue1 . equals ( timeValue2 ) ,
61
61
'instances encapsulating different values are not equal'
62
62
) ;
63
+ } ,
64
+
65
+ /**
66
+ * Tests the effect of the private pad() function, relevant in getSortKey() and toJSON().
67
+ *
68
+ * @since 0.7
69
+ *
70
+ * @param {QUnit } assert
71
+ */
72
+ testPad : function ( assert ) {
73
+ var testCases = {
74
+ '1-1-1T01:01:01Z' : '+00000000001-01-01T01:01:01Z' ,
75
+ '12-00-00T00:00:00Z' : '+00000000012-00-00T00:00:00Z' ,
76
+ '1234567890-00-00T00:00:00Z' : '+01234567890-00-00T00:00:00Z' ,
77
+ '12345678901-00-00T00:00:00Z' : '+12345678901-00-00T00:00:00Z' ,
78
+ '123456789012-00-00T00:00:00Z' : '+123456789012-00-00T00:00:00Z' ,
79
+ '1234567890123456-00-00T00:00:00Z' : '+1234567890123456-00-00T00:00:00Z'
80
+ } ;
81
+
82
+ for ( var iso8601 in testCases ) {
83
+ var expected = testCases [ iso8601 ] ,
84
+ actual = new dv . TimeValue ( iso8601 ) . getSortKey ( ) ;
85
+
86
+ assert . ok (
87
+ expected === actual ,
88
+ 'Expected getSortKey() to return "' + expected + '", got "' + actual + '"'
89
+ ) ;
90
+
91
+ }
63
92
}
64
93
65
94
} ) ;
You can’t perform that action at this time.
0 commit comments