11/*
22 date_strftime.c: based on a public-domain implementation of ANSI C
3- library routine of strftime, which is originally written by Arnold
3+ library routine strftime, which is originally written by Arnold
44 Robbins.
55 */
66
@@ -84,7 +84,8 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
8484 if (precision <= 0) precision = (def_prec); \
8585 if (flags & BIT_OF(LEFT)) precision = 1; \
8686 l = snprintf(s, endp - s, \
87- ((padding == '0' || (!padding && (def_pad) == '0')) ? "%0*"fmt : "%*"fmt), \
87+ ((padding == '0' || (!padding && (def_pad) == '0')) ? \
88+ "%0*"fmt : "%*"fmt), \
8889 precision, (val)); \
8990 if (l < 0) goto err; \
9091 s += l; \
@@ -121,8 +122,8 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
121122 result = rb_str_format(2, args, rb_str_new2("%0*"fmt)); \
122123 else \
123124 result = rb_str_format(2, args, rb_str_new2("%*"fmt)); \
124- l = strlcpy(s, StringValueCStr(result), endp- s); \
125- if ((size_t)(endp- s) <= l) \
125+ l = strlcpy(s, StringValueCStr(result), endp - s); \
126+ if ((size_t)(endp - s) <= l) \
126127 goto err; \
127128 s += l; \
128129 } \
@@ -176,14 +177,14 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
176177 i = 1 , tp = "?" ;
177178 else {
178179 if (* format == 'B' )
179- i = strlen (tp = months_l [mon - 1 ]);
180+ i = strlen (tp = months_l [mon - 1 ]);
180181 else
181- i = 3 , tp = months_l [mon - 1 ];
182+ i = 3 , tp = months_l [mon - 1 ];
182183 }
183184 }
184185 break ;
185186
186- case 'C' :
187+ case 'C' : /* century (year/100) */
187188 FMTV ('0' , 2 , "d" , div (tmx_year , INT2FIX (100 )));
188189 continue ;
189190
@@ -272,15 +273,16 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
272273 subsec = div (subsec , INT2FIX (1 ));
273274
274275 if (FIXNUM_P (subsec )) {
275- (void )snprintf (s , endp - s , "%0*ld" , precision , FIX2LONG (subsec ));
276+ (void )snprintf (s , endp - s , "%0*ld" ,
277+ precision , FIX2LONG (subsec ));
276278 s += precision ;
277279 }
278280 else {
279281 VALUE args [2 ], result ;
280282 args [0 ] = INT2FIX (precision );
281283 args [1 ] = subsec ;
282284 result = rb_str_format (2 , args , rb_str_new2 ("%0*d" ));
283- (void )strlcpy (s , StringValueCStr (result ), endp - s );
285+ (void )strlcpy (s , StringValueCStr (result ), endp - s );
284286 s += precision ;
285287 }
286288 }
@@ -321,7 +323,7 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
321323 i = 2 ;
322324 break ;
323325
324- case 'Q' :
326+ case 'Q' : /* microseconds since Unix epoch */
325327 FMTV ('0' , 1 , "d" , tmx_msecs );
326328 continue ;
327329
@@ -338,7 +340,7 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
338340 FMT ('0' , 2 , "d" , v );
339341 continue ;
340342
341- case 's' :
343+ case 's' : /* seconds since Unix epoch */
342344 FMTV ('0' , 1 , "d" , tmx_secs );
343345 continue ;
344346
@@ -352,8 +354,7 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
352354 FMT ('0' , 2 , "d" , v );
353355 continue ;
354356
355- case 'u' :
356- /* ISO 8601: Weekday as a decimal number [1 (Monday) - 7] */
357+ case 'u' : /* weekday, Monday == 1, 1 - 7 */
357358 v = range (1 , tmx_cwday , 7 );
358359 FMT ('0' , 1 , "d" , v );
359360 continue ;
@@ -413,7 +414,7 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
413414 }
414415 break ;
415416
416- case 'z' : /* time zone offset east of UTC e.g. -0600 */
417+ case 'z' : /* offset from UTC */
417418 {
418419 long off , aoff ;
419420 int hl , hw ;
@@ -434,32 +435,35 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
434435
435436 switch (colons ) {
436437 case 0 : /* %z -> +hhmm */
437- precision = precision <= (3 + hw ) ? hw : precision - 3 ;
438+ precision = precision <= (3 + hw ) ? hw : precision - 3 ;
438439 NEEDS (precision + 3 );
439440 break ;
440441
441442 case 1 : /* %:z -> +hh:mm */
442- precision = precision <= (4 + hw ) ? hw : precision - 4 ;
443+ precision = precision <= (4 + hw ) ? hw : precision - 4 ;
443444 NEEDS (precision + 4 );
444445 break ;
445446
446447 case 2 : /* %::z -> +hh:mm:ss */
447- precision = precision <= (7 + hw ) ? hw : precision - 7 ;
448+ precision = precision <= (7 + hw ) ? hw : precision - 7 ;
448449 NEEDS (precision + 7 );
449450 break ;
450451
451452 case 3 : /* %:::z -> +hh[:mm[:ss]] */
452453 {
453454 if (aoff % 3600 == 0 ) {
454- precision = precision <= (1 + hw ) ? hw : precision - 1 ;
455+ precision = precision <= (1 + hw ) ?
456+ hw : precision - 1 ;
455457 NEEDS (precision + 3 );
456458 }
457459 else if (aoff % 60 == 0 ) {
458- precision = precision <= (4 + hw ) ? hw : precision - 4 ;
460+ precision = precision <= (4 + hw ) ?
461+ hw : precision - 4 ;
459462 NEEDS (precision + 4 );
460463 }
461464 else {
462- precision = precision <= (7 + hw ) ? hw : precision - 7 ;
465+ precision = precision <= (7 + hw ) ?
466+ hw : precision - 7 ;
463467 NEEDS (precision + 7 );
464468 }
465469 }
0 commit comments