• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FXCRT_CFX_DATETIME_H_
8 #define CORE_FXCRT_CFX_DATETIME_H_
9 
10 #include "core/fxcrt/fx_system.h"
11 
12 bool FX_IsLeapYear(int32_t iYear);
13 uint8_t FX_DaysInMonth(int32_t iYear, uint8_t iMonth);
14 
15 class CFX_DateTime {
16  public:
17   static CFX_DateTime Now();
18 
CFX_DateTime()19   CFX_DateTime()
20       : year_(0),
21         month_(0),
22         day_(0),
23         hour_(0),
24         minute_(0),
25         second_(0),
26         millisecond_(0) {}
CFX_DateTime(int32_t year,uint8_t month,uint8_t day,uint8_t hour,uint8_t minute,uint8_t second,uint16_t millisecond)27   CFX_DateTime(int32_t year,
28                uint8_t month,
29                uint8_t day,
30                uint8_t hour,
31                uint8_t minute,
32                uint8_t second,
33                uint16_t millisecond)
34       : year_(year),
35         month_(month),
36         day_(day),
37         hour_(hour),
38         minute_(minute),
39         second_(second),
40         millisecond_(millisecond) {}
41 
Reset()42   void Reset() {
43     year_ = 0;
44     month_ = 0;
45     day_ = 0;
46     hour_ = 0;
47     minute_ = 0;
48     second_ = 0;
49     millisecond_ = 0;
50   }
51 
IsSet()52   bool IsSet() const {
53     return year_ != 0 || month_ != 0 || day_ != 0 || hour_ != 0 ||
54            minute_ != 0 || second_ != 0 || millisecond_ != 0;
55   }
56 
SetDate(int32_t year,uint8_t month,uint8_t day)57   void SetDate(int32_t year, uint8_t month, uint8_t day) {
58     year_ = year;
59     month_ = month;
60     day_ = day;
61   }
62 
SetTime(uint8_t hour,uint8_t minute,uint8_t second,uint16_t millisecond)63   void SetTime(uint8_t hour,
64                uint8_t minute,
65                uint8_t second,
66                uint16_t millisecond) {
67     hour_ = hour;
68     minute_ = minute;
69     second_ = second;
70     millisecond_ = millisecond;
71   }
72 
GetYear()73   int32_t GetYear() const { return year_; }
GetMonth()74   uint8_t GetMonth() const { return month_; }
GetDay()75   uint8_t GetDay() const { return day_; }
GetHour()76   uint8_t GetHour() const { return hour_; }
GetMinute()77   uint8_t GetMinute() const { return minute_; }
GetSecond()78   uint8_t GetSecond() const { return second_; }
GetMillisecond()79   uint16_t GetMillisecond() const { return millisecond_; }
80   int32_t GetDayOfWeek() const;
81 
82   bool operator==(const CFX_DateTime& other) const;
83 
84  private:
85   int32_t year_;
86   uint8_t month_;
87   uint8_t day_;
88   uint8_t hour_;
89   uint8_t minute_;
90   uint8_t second_;
91   uint16_t millisecond_;
92 };
93 
94 #if _FX_OS_ != _FX_OS_ANDROID_
95 #pragma pack(push, 1)
96 #endif
97 struct FX_TIMEZONE {
98   int8_t tzHour;
99   uint8_t tzMinute;
100 };
101 #if _FX_OS_ != _FX_OS_ANDROID_
102 #pragma pack(pop)
103 #endif
104 
105 #endif  // CORE_FXCRT_CFX_DATETIME_H_
106