]> git.sur5r.net Git - cc65/blobdiff - libsrc/common/strftime.c
The spans do now contain the size of a span, no longer the end offset.
[cc65] / libsrc / common / strftime.c
index 979f40c2a4519b803d18702837bbf345b7598708..baaa6fbe81106c3a055ec3205c92693592f30d0c 100644 (file)
@@ -40,7 +40,7 @@
 
 
 /* Use static local variables for speed */
-#pragma staticlocals (on);
+#pragma static-locals (on);
 
 
 
@@ -67,7 +67,6 @@ size_t __fastcall__ strftime (char* buf, size_t bufsize, const char* format,
     char        c;
     char        arg[40];
     const char* argptr;
-    unsigned    week;
 
     /* Copy until we reach the end of the format string or a format specifier */
     count = 0;
@@ -132,20 +131,12 @@ size_t __fastcall__ strftime (char* buf, size_t bufsize, const char* format,
                     break;
 
                 case 'U':
-                    week = tm->tm_yday / 7;
-                    if (tm->tm_mday % 7 > tm->tm_wday) {
-                        ++week;
-                    }
-                    sprintf (arg, "%02u", week);
+                    sprintf (arg, "%02d", (tm->tm_yday + 7 - tm->tm_wday) / 7);
                     break;
 
                 case 'W':
-                    /* ### This one is buggy */
-                    week = tm->tm_yday / 7;
-                    if (tm->tm_mday % 7 > tm->tm_wday) {
-                        ++week;
-                    }
-                    sprintf (arg, "%2u", week);
+                    sprintf (arg, "%02d",
+                             (tm->tm_yday + 7 - (tm->tm_wday? tm->tm_wday - 1 : 6)) / 7);
                     break;
 
                 case 'X':
@@ -166,7 +157,7 @@ size_t __fastcall__ strftime (char* buf, size_t bufsize, const char* format,
                     break;
 
                 case 'b':
-                    sprintf (arg, "%.3s", months[tm->tm_mday]);
+                    sprintf (arg, "%.3s", months[tm->tm_mon]);
                     break;
 
                 case 'c':