ECMapiUtils.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include <kopano/platform.h>
  18. #include <pthread.h>
  19. #include <mapix.h>
  20. #include <ctime>
  21. #include <iostream>
  22. #include "ECMapiUtils.h"
  23. namespace KC {
  24. // Returns the FILETIME as GM-time
  25. FILETIME vmimeDatetimeToFiletime(vmime::datetime dt) {
  26. FILETIME sFiletime;
  27. struct tm when;
  28. int iYear, iMonth, iDay, iHour, iMinute, iSecond, iZone;
  29. time_t lTmpTime;
  30. dt.getDate( iYear, iMonth, iDay );
  31. dt.getTime( iHour, iMinute, iSecond, iZone );
  32. when.tm_hour = iHour;
  33. when.tm_min = iMinute - iZone; // Zone is expressed in minutes. mktime() will normalize negative values or values over 60
  34. when.tm_sec = iSecond;
  35. when.tm_mon = iMonth - 1;
  36. when.tm_mday = iDay;
  37. when.tm_year = iYear - 1900;
  38. when.tm_isdst = -1; // ignore dst
  39. lTmpTime = timegm(&when);
  40. UnixTimeToFileTime(lTmpTime, &sFiletime);
  41. return sFiletime;
  42. }
  43. vmime::datetime FiletimeTovmimeDatetime(FILETIME ft) {
  44. time_t tmp;
  45. struct tm convert;
  46. FileTimeToUnixTime(ft, &tmp);
  47. gmtime_safe(&tmp, &convert);
  48. return vmime::datetime(convert.tm_year + 1900, convert.tm_mon + 1, convert.tm_mday, convert.tm_hour, convert.tm_min, convert.tm_sec);
  49. }
  50. } /* namespace */