summaryrefslogtreecommitdiff
path: root/xfa/fgas/localization/fgas_datetime.h
blob: 1f9f19d2c19603c30b784595fbc035fe8b961b58 (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
// 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 XFA_FGAS_LOCALIZATION_FGAS_DATETIME_H_
#define XFA_FGAS_LOCALIZATION_FGAS_DATETIME_H_

#include "core/fxcrt/fx_system.h"

class CFX_Unitime;
class CFX_DateTime;

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

class CFX_Unitime {
 public:
  CFX_Unitime() { m_iUnitime = 0; }
  explicit CFX_Unitime(int64_t iUnitime) { m_iUnitime = iUnitime; }

  int64_t ToInt64() const { return m_iUnitime; }

  void Now();
  void Set(int32_t year,
           uint8_t month,
           uint8_t day,
           uint8_t hour,
           uint8_t minute,
           uint8_t second,
           uint16_t millisecond);
  void Set(int64_t t) { m_iUnitime = t; }

  int32_t GetYear() const;
  uint8_t GetMonth() const;
  uint8_t GetDay() const;
  uint8_t GetHour() const;
  uint8_t GetMinute() const;
  uint8_t GetSecond() const;
  uint16_t GetMillisecond() const;

  CFX_Unitime operator+(const CFX_Unitime& t2) const {
    return CFX_Unitime(m_iUnitime + t2.m_iUnitime);
  }

 private:
  int64_t m_iUnitime;
};

#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

class CFX_DateTime {
 public:
  CFX_DateTime() {}
  ~CFX_DateTime() {}

  bool Set(int32_t year, uint8_t month, uint8_t day);
  int32_t GetDayOfWeek() const;

 private:
#if _FX_OS_ != _FX_ANDROID_
#pragma pack(push, 1)
#endif
  struct FX_DATE {
    int32_t year;
    uint8_t month;
    uint8_t day;
  };

  struct FX_TIME {
    uint8_t hour;
    uint8_t minute;
    uint8_t second;
    uint16_t millisecond;
  };

  struct FX_DATETIME {
    union {
      FX_DATE sDate;
      FX_DATE aDate;
    } Date;
    union {
      FX_TIME sTime;
      FX_TIME aTime;
    } Time;
  };

#if _FX_OS_ != _FX_ANDROID_
#pragma pack(pop)
#endif
  FX_DATETIME m_DateTime;
};

#endif  // XFA_FGAS_LOCALIZATION_FGAS_DATETIME_H_