summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_datetime.h
blob: 272c2496ccf0bd1ae2a36e9c86bbbb10ef67aa65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef CORE_FXCRT_CFX_DATETIME_H_
#define CORE_FXCRT_CFX_DATETIME_H_

#include "core/fxcrt/fx_system.h"

bool FX_IsLeapYear(int32_t iYear);
uint8_t FX_DaysInMonth(int32_t iYear, uint8_t iMonth);

class CFX_DateTime {
 public:
  CFX_DateTime()
      : year_(0),
        month_(0),
        day_(0),
        hour_(0),
        minute_(0),
        second_(0),
        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)
      : year_(year),
        month_(month),
        day_(day),
        hour_(hour),
        minute_(minute),
        second_(second),
        millisecond_(millisecond) {}

  void Now();

  void Reset() {
    year_ = 0;
    month_ = 0;
    day_ = 0;
    hour_ = 0;
    minute_ = 0;
    second_ = 0;
    millisecond_ = 0;
  }

  bool IsSet() const {
    return year_ != 0 || month_ != 0 || day_ != 0 || hour_ != 0 ||
           minute_ != 0 || second_ != 0 || millisecond_ != 0;
  }

  void SetDate(int32_t year, uint8_t month, uint8_t day) {
    year_ = year;
    month_ = month;
    day_ = day;
  }

  void SetTime(uint8_t hour,
               uint8_t minute,
               uint8_t second,
               uint16_t millisecond) {
    hour_ = hour;
    minute_ = minute;
    second_ = second;
    millisecond_ = millisecond;
  }

  int32_t GetYear() const { return year_; }
  uint8_t GetMonth() const { return month_; }
  uint8_t GetDay() const { return day_; }
  uint8_t GetHour() const { return hour_; }
  uint8_t GetMinute() const { return minute_; }
  uint8_t GetSecond() const { return second_; }
  uint16_t GetMillisecond() const { return millisecond_; }
  int32_t GetDayOfWeek() const;

  bool operator==(const CFX_DateTime& other) const;

 private:
  int32_t year_;
  uint8_t month_;
  uint8_t day_;
  uint8_t hour_;
  uint8_t minute_;
  uint8_t second_;
  uint16_t millisecond_;
};

#if _FX_OS_ != _FX_ANDROID_
#pragma pack(push, 1)
#endif
struct FX_TIMEZONE {
  int8_t tzHour;
  uint8_t tzMinute;
};
#if _FX_OS_ != _FX_ANDROID_
#pragma pack(pop)
#endif

#endif  // CORE_FXCRT_CFX_DATETIME_H_