smbtime.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "headers.h"
  2. void
  3. smbplan9time2datetime(ulong time, int tzoff, ushort *datep, ushort *timep)
  4. {
  5. Tm *tm;
  6. if (tzoff < 0)
  7. time -= (ulong)-tzoff;
  8. else
  9. time += tzoff;
  10. tm = gmtime(time);
  11. *datep = (tm->mday) | ((tm->mon + 1) << 5) | ((tm->year - 80) << 9);
  12. *timep = (tm->sec >> 1) | (tm->min << 5) | (tm->hour << 11);
  13. }
  14. ulong
  15. smbdatetime2plan9time(ushort date, ushort time, int tzoff)
  16. {
  17. Tm tm;
  18. strcpy(tm.zone, "GMT");
  19. tm.mday = date & 0x1f;
  20. tm.mon = ((date >> 5) & 0xf) - 1;
  21. tm.year = (date >> 9) + 80;
  22. tm.yday = 0;
  23. tm.sec = (time & 0x1f) << 1;
  24. tm.min = (time >> 5) & 0x3f;
  25. tm.hour = time >> 11;
  26. smblogprint(-1, "smbdatetime2plan9time: converting %d/%d/%d %d:%d:%d\n",
  27. tm.year + 1900, tm.mon + 1, tm.mday, tm.hour, tm.min, tm.sec);
  28. return tm2sec(&tm) - tzoff;
  29. }
  30. vlong
  31. smbplan9time2time(ulong time)
  32. {
  33. return ((vlong)time + 11644473600LL) * 10000000;
  34. }
  35. ulong
  36. smbtime2plan9time(vlong nttime)
  37. {
  38. return (nttime / 10000000 - 11644473600LL);
  39. }
  40. ulong
  41. smbplan9time2utime(ulong time, int tzoff)
  42. {
  43. if (tzoff < 0)
  44. time -= (ulong)-tzoff;
  45. else
  46. time += tzoff;
  47. return time;
  48. }
  49. ulong
  50. smbutime2plan9time(ulong utime, int tzoff)
  51. {
  52. if (tzoff < 0)
  53. utime += (ulong)-tzoff;
  54. else
  55. utime -= tzoff;
  56. return utime;
  57. }