suitcase

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

caldate_fmt.c (530B)


      1 #include <tai/caldate.h>
      2 
      3 unsigned int caldate_fmt(char *s, struct caldate *cd)
      4 {
      5   long x;
      6   int i = 0;
      7 
      8   x = cd->year; if (x < 0) x = -x; do { ++i; x /= 10; } while(x);
      9 
     10   if (s) {
     11     x = cd->year;
     12     if (x < 0) { x = -x; *s++ = '-'; }
     13     s += i; do { *--s = '0' + (x % 10); x /= 10; } while(x); s += i;
     14 
     15     x = cd->month;
     16     s[0] = '-'; s[2] = '0' + (x % 10); x /= 10; s[1] = '0' + (x % 10);
     17 
     18     x = cd->day;
     19     s[3] = '-'; s[5] = '0' + (x % 10); x /= 10; s[4] = '0' + (x % 10);
     20   }
     21 
     22   return (cd->year < 0) + i + 6;
     23 }