fmt_ptime.c (1120B)
1 #include <time.h> 2 #include "fmt_ptime.h" 3 #include "fmt.h" 4 5 static unsigned int fmt_ptime2(char *s, struct taia *ta, char sep) { 6 struct tm *t; 7 time_t u; 8 9 if (ta->sec.x < 4611686018427387914ULL) return(0); /* impossible? */ 10 u =ta->sec.x -4611686018427387914ULL; 11 if (! (t =gmtime((time_t*)&u))) return(0); 12 fmt_ulong(s, 1900 +t->tm_year); 13 s[4] ='-'; fmt_uint0(&s[5], t->tm_mon +1, 2); 14 s[7] ='-'; fmt_uint0(&s[8], t->tm_mday, 2); 15 s[10] =sep; fmt_uint0(&s[11], t->tm_hour, 2); 16 s[13] =':'; fmt_uint0(&s[14], t->tm_min, 2); 17 s[16] =':'; fmt_uint0(&s[17], t->tm_sec, 2); 18 s[19] ='.'; fmt_uint0(&s[20], ta->nano, 9); 19 return(25); 20 } 21 22 unsigned int fmt_ptime(char *s, struct taia *ta) { 23 return(fmt_ptime2(s, ta, '_')); 24 } 25 26 unsigned int fmt_ptime_iso8601(char *s, struct taia *ta) { 27 return(fmt_ptime2(s, ta, 'T')); 28 } 29 30 unsigned int fmt_taia(char *s, struct taia *t) { 31 static char hex[16] ="0123456789abcdef"; 32 static char pack[TAIA_PACK]; 33 int i; 34 35 taia_pack(pack, t); 36 s[0] ='@'; 37 for (i =0; i < 12; ++i) { 38 s[i *2 +1] =hex[(pack[i] >>4) &15]; 39 s[i *2 +2] =hex[pack[i] &15]; 40 } 41 return(25); 42 }