Skip to content
This repository

Added leftZeroFill to GGGG and gggg formats #1396

Merged
merged 5 commits into from 3 months ago

2 participants

mdxs Iskren Ivov Chernev
mdxs

Added leftZeroFill to GGGG and gggg formats (similar to how YYYY and other year formats do). Expanded testing for these cases; and in the process added testing for W and fixed a typo in some existing tests.

Iskren Ivov Chernev ichernev merged commit f5e8acc into from January 09, 2014
Iskren Ivov Chernev ichernev closed this January 09, 2014
mdxs mdxs deleted the branch January 09, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
4  moment.js
@@ -181,7 +181,7 @@
181 181
                 return leftZeroFill(this.weekYear() % 100, 2);
182 182
             },
183 183
             gggg : function () {
184  
-                return this.weekYear();
  184
+                return leftZeroFill(this.weekYear(), 4);
185 185
             },
186 186
             ggggg : function () {
187 187
                 return leftZeroFill(this.weekYear(), 5);
@@ -190,7 +190,7 @@
190 190
                 return leftZeroFill(this.isoWeekYear() % 100, 2);
191 191
             },
192 192
             GGGG : function () {
193  
-                return this.isoWeekYear();
  193
+                return leftZeroFill(this.isoWeekYear(), 4);
194 194
             },
195 195
             GGGGG : function () {
196 196
                 return leftZeroFill(this.isoWeekYear(), 5);
35  test/moment/format.js
@@ -209,7 +209,7 @@ exports.format = {
209 209
         test.done();
210 210
     },
211 211
 
212  
-    "weeks format" : function (test) {
  212
+    "iso week formats" : function (test) {
213 213
 
214 214
         // http://en.wikipedia.org/wiki/ISO_week_date
215 215
         var cases = {
@@ -227,13 +227,18 @@ exports.format = {
227 227
             "2009-12-31": "2009-53",
228 228
             "2010-01-01": "2009-53",
229 229
             "2010-01-02": "2009-53",
230  
-            "2010-01-03": "2009-53"
231  
-        }, i, iso, the;
  230
+            "2010-01-03": "2009-53",
  231
+            "404-12-31": "0404-53",
  232
+            "405-12-31": "0405-52"
  233
+        }, i, isoWeek, formatted2, formatted1;
232 234
 
233 235
         for (i in cases) {
234  
-            iso = cases[i].split('-').pop();
235  
-            the = moment(i).format('WW');
236  
-            test.equal(iso, the, i + ": should be " + iso + ", but " + the);
  236
+            isoWeek = cases[i].split('-').pop();
  237
+            formatted2 = moment(i).format('WW');
  238
+            test.equal(isoWeek, formatted2, i + ": should be " + isoWeek + ", but " + formatted2);
  239
+            isoWeek = isoWeek.replace(/^0+/, '');
  240
+            formatted1 = moment(i).format('W');
  241
+            test.equal(isoWeek, formatted1, i + ": should be " + isoWeek + ", but " + formatted1);
237 242
         }
238 243
 
239 244
         test.done();
@@ -241,7 +246,7 @@ exports.format = {
241 246
 
242 247
     "iso week year formats" : function (test) {
243 248
 
244  
-        // http://en.wikipedia.org/wiki/ISO_week
  249
+        // http://en.wikipedia.org/wiki/ISO_week_date
245 250
         var cases = {
246 251
             "2005-01-02": "2004-53",
247 252
             "2005-12-31": "2005-52",
@@ -257,13 +262,15 @@ exports.format = {
257 262
             "2009-12-31": "2009-53",
258 263
             "2010-01-01": "2009-53",
259 264
             "2010-01-02": "2009-53",
260  
-            "2010-01-03": "2009-53"
  265
+            "2010-01-03": "2009-53",
  266
+            "404-12-31": "0404-53",
  267
+            "405-12-31": "0405-52"
261 268
         }, i, isoWeekYear, formatted5, formatted4, formatted2;
262 269
 
263 270
         for (i in cases) {
264 271
             isoWeekYear = cases[i].split('-')[0];
265 272
             formatted5 = moment(i).format('GGGGG');
266  
-            test.equal('0' + isoWeekYear, formatted5, i + ": should be " + isoWeekYear + ", but " + formatted4);
  273
+            test.equal('0' + isoWeekYear, formatted5, i + ": should be " + isoWeekYear + ", but " + formatted5);
267 274
             formatted4 = moment(i).format('GGGG');
268 275
             test.equal(isoWeekYear, formatted4, i + ": should be " + isoWeekYear + ", but " + formatted4);
269 276
             formatted2 = moment(i).format('GG');
@@ -275,7 +282,7 @@ exports.format = {
275 282
 
276 283
     "week year formats" : function (test) {
277 284
 
278  
-        // http://en.wikipedia.org/wiki/ISO_week
  285
+        // http://en.wikipedia.org/wiki/ISO_week_date
279 286
         var cases = {
280 287
             "2005-01-02": "2004-53",
281 288
             "2005-12-31": "2005-52",
@@ -291,14 +298,16 @@ exports.format = {
291 298
             "2009-12-31": "2009-53",
292 299
             "2010-01-01": "2009-53",
293 300
             "2010-01-02": "2009-53",
294  
-            "2010-01-03": "2009-53"
295  
-        }, i, formatted5, formatted4, formatted2, isoWeekYear;
  301
+            "2010-01-03": "2009-53",
  302
+            "404-12-31": "0404-53",
  303
+            "405-12-31": "0405-52"
  304
+        }, i, isoWeekYear, formatted5, formatted4, formatted2;
296 305
 
297 306
         moment.lang('en-gb'); // 1, 4
298 307
         for (i in cases) {
299 308
             isoWeekYear = cases[i].split('-')[0];
300 309
             formatted5 = moment(i).format('ggggg');
301  
-            test.equal('0' + isoWeekYear, formatted5, i + ": should be " + isoWeekYear + ", but " + formatted4);
  310
+            test.equal('0' + isoWeekYear, formatted5, i + ": should be " + isoWeekYear + ", but " + formatted5);
302 311
             formatted4 = moment(i).format('gggg');
303 312
             test.equal(isoWeekYear, formatted4, i + ": should be " + isoWeekYear + ", but " + formatted4);
304 313
             formatted2 = moment(i).format('gg');
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.