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 @@ -332,7 +332,12 @@ SELF.getPrecisionById = function( id ) {
332
332
* @return {string }
333
333
*/
334
334
function pad ( number , digits ) {
335
- return ( ( 1e12 + Math . abs ( number ) ) . toString ( ) ) . slice ( - digits ) ;
335
+ number = String ( Math . abs ( number ) ) ;
336
+ if ( number . length >= digits ) {
337
+ return number ;
338
+ }
339
+
340
+ return new Array ( digits - number . length + 1 ) . join ( '0' ) + number ;
336
341
}
337
342
338
343
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