Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
840 B

  1. #include "fmt.h"
  2. #include "byte.h"
  3. #include <time.h>
  4. static unsigned int fmt_2digits(char* dest,int i) {
  5. dest[0]=(char)((i/10)+'0');
  6. dest[1]=(char)((i%10)+'0');
  7. return 2;
  8. }
  9. size_t fmt_iso8601(char* dest,time_t t) {
  10. #ifdef _WIN32
  11. struct tm tmp;
  12. struct tm* x=&tmp;
  13. gmtime_s(&tmp,&t); // can't recover from when this fails
  14. #else
  15. struct tm* x=gmtime(&t);
  16. #endif
  17. size_t i;
  18. if (dest==0) return sizeof("2014-05-27T19:22:16Z")-1;
  19. /* "2014-05-27T19:22:16Z" */
  20. i=fmt_ulong(dest,(x->tm_year+1900));
  21. dest[i++]='-';
  22. i+=fmt_2digits(dest+i,x->tm_mon+1);
  23. dest[i++]='-';
  24. i+=fmt_2digits(dest+i,x->tm_mday);
  25. dest[i++]='T';
  26. i+=fmt_2digits(dest+i,x->tm_hour);
  27. i+=fmt_str(dest+i,":");
  28. i+=fmt_2digits(dest+i,x->tm_min);
  29. i+=fmt_str(dest+i,":");
  30. i+=fmt_2digits(dest+i,x->tm_sec);
  31. i+=fmt_str(dest+i,"Z");
  32. return i;
  33. }