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 @@ -336,7 +336,12 @@ SELF.getPrecisionById = function( id ) {
336
336
* @return {string }
337
337
*/
338
338
function pad ( number , digits ) {
339
- return ( ( 1e12 + Math . abs ( number ) ) . toString ( ) ) . slice ( - digits ) ;
339
+ number = String ( Math . abs ( number ) ) ;
340
+ if ( number . length >= digits ) {
341
+ return number ;
342
+ }
343
+
344
+ return new Array ( digits - number . length + 1 ) . join ( '0' ) + number ;
340
345
}
341
346
342
347
dv . registerDataValue ( SELF ) ;
Original file line number Diff line number Diff line change @@ -43,6 +43,35 @@ define( [
43
43
precision : 9
44
44
} ]
45
45
] ;
46
+ } ,
47
+
48
+ /**
49
+ * Tests the effect of the private pad() function, relevant in getSortKey() and toJSON().
50
+ *
51
+ * @since 0.7
52
+ *
53
+ * @param {QUnit } assert
54
+ */
55
+ testPad : function ( assert ) {
56
+ var testCases = {
57
+ '1-1-1T01:01:01Z' : '+00000000001-01-01T01:01:01Z' ,
58
+ '12-00-00T00:00:00Z' : '+00000000012-00-00T00:00:00Z' ,
59
+ '1234567890-00-00T00:00:00Z' : '+01234567890-00-00T00:00:00Z' ,
60
+ '12345678901-00-00T00:00:00Z' : '+12345678901-00-00T00:00:00Z' ,
61
+ '123456789012-00-00T00:00:00Z' : '+123456789012-00-00T00:00:00Z' ,
62
+ '1234567890123456-00-00T00:00:00Z' : '+1234567890123456-00-00T00:00:00Z'
63
+ } ;
64
+
65
+ for ( var iso8601 in testCases ) {
66
+ var expected = testCases [ iso8601 ] ,
67
+ actual = new dv . TimeValue ( iso8601 ) . getSortKey ( ) ;
68
+
69
+ assert . ok (
70
+ expected === actual ,
71
+ 'Expected getSortKey() to return "' + expected + '", got "' + actual + '"'
72
+ ) ;
73
+
74
+ }
46
75
}
47
76
48
77
} ) ;
You can’t perform that action at this time.
0 commit comments