TimeZone.hpp
1 /*
2 * @Author: xiong
3 * @Date: 2022/9/23
4 */
5 
6 #ifndef EMX_TimeZone_HPP
7 #define EMX_TimeZone_HPP
8 
9 #include "EmxCore.hpp"
10 
11 namespace Emx {
16  class TimeZone {
17  public:
18  TimeZone() { memset(m_zone, 0, sizeof(m_zone)); }
19 
20  static const int MaxZoneSize = 128;
26 
32  ErrCodeE Set(const char *zone);
33 
39 
44  char *Get() { return m_zone; }
45 
50  void GetZoneList(std::vector<std::string> &list);
51 
52  private:
53  void GetZoneListDir(const char *path, const std::string &name, std::vector<std::string> &list);
54 
55  char m_zone[MaxZoneSize];
56  };
57 
59  class TimeZone2 {
60  // tz-data
61  // # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
62  // Rule EMX 1970 max - Jan 25 18:14 1:00 D
63  // Rule EMX 1970 max - Jan 25 19:15 0 S
64 
65  // # Zone NAME STDOFF RULES FORMAT [UNTIL]
66  // Zone localtime 8:00 EMX C%sT
67  //
68  public:
69  struct ZoneParam {
70  char gmt[12];// eg."GMT+08:45"
71  struct Daylight {
72  bool ena;
73  char save[8];// 夏令时调整时常eg."1:10",调快一个小时零十分钟
74  struct Rule {
75  char in[4]; // 规则月份 eg."Jan"/"Feb"/"Aug"...
76  char on[12];// 规则日期,这部分规则比较复杂
77  char at[8]; // 规则时间 eg."2:00",凌晨2点
78  // on 规则日期解析
79  // 当on为具体数字时,代表这个月的几号,例如"25"代表in这个月的25开始/结束
80  // 夏令时一般不是具体几号,而是以某个周日或周几为开始/结束
81  // on支持这种方式,例如"Sun>=1"代表in这个月1号或1号后的首个周日开始结束
82  // "Thu>19"代表in这个月19号后的首个周四开始/结束
83  // 另外还可以使用lastXxx规则
84  // "lastXxx"代表这个月的最后一个周几,例如"lastSun"代表最后一个周日
85  } into, leave;//进入离开夏令时规则
87  };
88  TimeZone2() {}
89  virtual ~TimeZone2() {}
90 
92 
98  static ErrCodeE Set(const ZoneParam &param);
99 
104  static ErrCodeE Get(ZoneParam &param) { return Load(param); }
105 
106  private:
107  static ErrCodeE Load(ZoneParam &param);
108  static ErrCodeE GenerateLocaltime(const ZoneParam &param);
109  };
111 }// namespace Emx
112 
113 #endif//EMX_TimeZone_HPP
根据用户输入的GMT时区信息和夏令时信息自动生成时区文件并配置localtime
Definition: TimeZone.hpp:59
TimeZone2()
Definition: TimeZone.hpp:88
static ErrCodeE InitDeviceTimeZone()
virtual ~TimeZone2()
Definition: TimeZone.hpp:89
static ErrCodeE Get(ZoneParam &param)
获取当前时区参数
Definition: TimeZone.hpp:104
static ErrCodeE Set(const ZoneParam &param)
设置系统时区
Definition: TimeZone.hpp:16
void GetZoneList(std::vector< std::string > &list)
获取时区文件列表
static const int MaxZoneSize
zone字符串最大大小
Definition: TimeZone.hpp:20
TimeZone()
Definition: TimeZone.hpp:18
ErrCodeE CopyTimeZoneToLocalTime()
将zone.json中的时区复制到localtime文件
ErrCodeE Load()
从flash中加载参数
ErrCodeE Set(const char *zone)
设置系统时区(更改zone.json同时配置时区文件)
char * Get()
获取当前时区文件名
Definition: TimeZone.hpp:44
ErrCodeE
错误码定义
Definition: EmxTypeDef.hpp:29
Definition: EmxGpio.hpp:10
char in[4]
Definition: TimeZone.hpp:75
char at[8]
Definition: TimeZone.hpp:77
char on[12]
Definition: TimeZone.hpp:76
Definition: TimeZone.hpp:71
struct Emx::TimeZone2::ZoneParam::Daylight::Rule into
struct Emx::TimeZone2::ZoneParam::Daylight::Rule leave
bool ena
Definition: TimeZone.hpp:72
char save[8]
Definition: TimeZone.hpp:73
Definition: TimeZone.hpp:69
char gmt[12]
Definition: TimeZone.hpp:70
struct Emx::TimeZone2::ZoneParam::Daylight daylight