PlistDate.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // PlistDate class appropriate for Apple Property Lists (plists). Part of
  3. // the PlistCpp Apple Property List (plist) serialization and parsing
  4. // library.
  5. //
  6. // https://github.com/animetrics/PlistCpp
  7. //
  8. // Copyright (c) 2011 Animetrics Inc. (marc@animetrics.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining a copy
  11. // of this software and associated documentation files (the "Software"), to deal
  12. // in the Software without restriction, including without limitation the rights
  13. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. // copies of the Software, and to permit persons to whom the Software is
  15. // furnished to do so, subject to the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be included in
  18. // all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. // THE SOFTWARE.
  27. #ifndef __PLIST_DATE_H__
  28. #define __PLIST_DATE_H__
  29. #include <ctime>
  30. #include <string>
  31. namespace Plist {
  32. class Date
  33. {
  34. public:
  35. Date();
  36. Date(int month, int day, int year, int hour24, int minute, int second, bool UTC);
  37. void set(int month, int day, int year, int hour24, int minute, int second, bool UTC);
  38. void setToCurrentTime();
  39. time_t secondsSinceDate(const Date& startDate) const;
  40. // returns -1 : first < second
  41. // 0 : first = second
  42. // 1 : first > second
  43. static int compare(const Date& first, const Date& second);
  44. bool operator > (const Date& rhs) const;
  45. bool operator < (const Date& rhs) const;
  46. bool operator == (const Date& rhs) const;
  47. // iso 8601 date string convention
  48. std::string timeAsXMLConvention() const;
  49. // iso 8601 date string convention
  50. void setTimeFromXMLConvention(const std::string& timeString);
  51. // Apple epoch is # of seconds since 01-01-2001. So we need to add the
  52. // number of seconds since 01-01-1970 which is proper unix epoch
  53. void setTimeFromAppleEpoch(double appleTime);
  54. time_t timeAsEpoch() const;
  55. // We need to subtract the number of seconds between 01-01-2001 and
  56. // 01-01-1970 to get Apple epoch from unix epoch
  57. double timeAsAppleEpoch() const;
  58. private:
  59. // stored as unix epoch, number of seconds since 01-01-1970
  60. time_t _time;
  61. };
  62. }
  63. #endif