acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
datetime.h
1// From department to datetime by camilo on 2022-11-19 04:41 <3ThomasBorregaardSorensen!!
2#pragma once
3
4
6#include "acme/platform/department.h"
7#include "earth_time_shift.h"
8#include "result.h"
10
11
12#define INTERNATIONAL_DATE_FORMAT_FOR_FILE "%Y-%m-%d"
13#define INTERNATIONAL_DATE_FORMAT "%Y-%m-%d"
14
15#define INTERNATIONAL_DATE_HOUR_FORMAT_FOR_FILE_WITH_NO_SPACES "%Y-%m-%d_%H"
16#define INTERNATIONAL_DATE_HOUR_FORMAT_FOR_FILE "%Y-%m-%d %H"
17#define INTERNATIONAL_DATE_HOUR_FORMAT "%Y-%m-%d %H"
18
19#define INTERNATIONAL_DATE_TIME_FORMAT_FOR_FILE_WITH_NO_SPACES "%Y-%m-%d_%H-%M-%S"
20#define INTERNATIONAL_DATE_TIME_FORMAT_FOR_FILE "%Y-%m-%d %H-%M-%S"
21#define INTERNATIONAL_DATE_TIME_FORMAT "%Y-%m-%d %H:%M:%S"
22
23
24CLASS_DECL_ACME ::i32 SWN(::i32 y,::i32 m,::i32 d);
25//where DP ("Days Passed") is given by:
26// DP( y, 1 ) = 0
27// DP( y, m+1 ) = DP( y, m ) + ML( y, m )
28CLASS_DECL_ACME ::i32 DP(::i32 y,::i32 m);
29CLASS_DECL_ACME ::i32 ML(::i32 y,::i32 m);
30CLASS_DECL_ACME ::i32 LEAP(::i32 y);
31CLASS_DECL_ACME ::i32 dayofweek(::i32 y,::i32 m,::i32 d); /* 0 = Sunday */
32CLASS_DECL_ACME ::i32 SDOW(::i32 y,::i32 m,::i32 d); // ( 0 = Monday, ..., 6 = Sunday )
33CLASS_DECL_ACME ::i32 DOW(::i32 y,::i32 m,::i32 d);
34CLASS_DECL_ACME ::i32 getDayOfWeek(::i32 month,::i32 day,::i32 year,::i32 CalendarSystem);
35
36
37namespace datetime
38{
39
40
41 class CLASS_DECL_ACME datetime:
42 virtual public ::platform::department
43 {
44 public:
45
46
47 //class CLASS_DECL_ACME international:
48 // virtual public ::object
49 //{
50 //public:
51
52 //
53 // international();
54
55
56 // virtual void initialize(::particle * pparticle) override;
57
58
59 // ::posix_time parse(const ::scoped_string & scopedstr);
60
61 // void parse_str(const ::scoped_string & scopedstr, ::property_set & set);
62 // ::earth::time parse_str(const ::scoped_string & scopedstr);
63
64
65 // string date_time_text(const ::earth::time & time, const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_TIME_FORMAT, const class ::time& timeshift = {});
66 // string date_time_text(const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_TIME_FORMAT, const class ::time& timeshift = {});
67 // string date_time_text_for_file(const class ::time& timeshift = {}, const ::earth::time & time = ::earth::time::now());
68
69 // string date_text(const ::earth::time & time, const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_FORMAT, const class ::time & timeshift = {});
70 // string date_text(const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_FORMAT, const class ::time & timeshift = {});
71 // string date_text_for_file(const class ::time & timeshift = {}, const ::earth::time & time = ::earth::time::now());
72 //
73
74 // //string local_get_date_time(const ::earth::time & time, const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_TIME_FORMAT);
75 // //string local_get_date_time(const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_TIME_FORMAT);
76 // //string local_get_date_time_for_file();
77
78
79 // string get_date_time_for_file_with_no_spaces(const class ::time& timeshift = {}, const ::earth::time & time = ::earth::time::now());
80 // //string local_get_date_time_for_file_with_no_spaces();
81
82
83 // inline string format(const ::scoped_string & strFormat = INTERNATIONAL_DATE_TIME_FORMAT, const class ::time& timeshift = {}) { return date_time_text(strFormat, timeshift); }
84 // inline string format(const ::earth::time & time, const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_TIME_FORMAT, const class ::time& timeshift = {}) { return date_time_text(time, strFormat, timeshift); }
85 //
86 // //inline string local_get(const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_TIME_FORMAT) { return local_get_date_time(strFormat); }
87 // //inline string local_get(const ::earth::time & time, const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_TIME_FORMAT) { return local_get_date_time(time, strFormat); }
88
89
90 // //inline string utc() { return utc_get(); }
91 // //inline string utc(const ::earth::time & time) { return utc_get(time); }
92 // //inline string local() { return local_get(); }
93 // //inline string local(const ::earth::time & time) { return local_get(time); }
94
95
96 //};
97
98
99// class CLASS_DECL_ACME str:
100// virtual public ::object
101// {
102// public:
103//
104//
105// department* m_pdatetime;
106//
107//
108// str();
109//
110// void initialize(::particle * pparticle) override;
111//
112// string get_date_time(const class ::time& timeshift = {});
113//
114//
115// };
116
117
118
119
120
121 //::pointer<::datetime::datetime::international> m_pinternational;
122 //::pointer<::datetime::datetime::str> m_pstr;
123
124
125
126
127 datetime();
128 ~datetime() override;
129
130
131 void initialize(::particle * pparticle) override;
132 void destroy() override;
133
134
135 ::i64 get_timestamp(::i32 year, ::i32 month, ::i32 day);
136
137
138 ::i32 get_month_day_count(::i32 year, ::i32 month);
139
140
141 ::i32 get_weekday(::i32 year, ::i32 month, ::i32 day);
142
143
144 posix_time strtotime(const ::text::context * pcontext, const ::scoped_string & scopedstr, posix_time time,::i32 iPath,::i32 & iPathCount, const class ::time& timezone = {});
145 posix_time strtotime(const ::text::context * pcontext, const ::scoped_string & scopedstr, ::i32 iPath,::i32 & iPathCount, const class ::time& timezone = {});
146
147
148 ::earth::time from_string(const ::text::context* pcontext, const ::scoped_string & scopedstr, const class ::time& timezone = {});
149
150
151 // 1 - domingo
152 string get_week_day_str(const ::text::context * pcontext,::i32 iWeekDay);
153 // 1 - domingo
154 string get_tiny_week_day_str(const ::text::context * pcontext,::i32 iWeekDay);
155 string get_month_str(const ::text::context * pcontext,::i32 iMonth);
156 string get_short_month_str(const ::text::context * pcontext,::i32 iMonth);
157
158 static posix_time s_mktime(::i32 iHour,::i32 iMinute,::i32 iSecond,::i32 iMonth,::i32 iDay,::i32 iYear, const class ::time& timezone = {});
159
160 //inline class international& international() { return *m_pinternational; }
161 //inline class str& str() { return* m_pstr; }
162
163 //string format(const ::scoped_string & scopedstr, const ::earth::time & time, const class ::time& timezone = {});
164 //string format(const ::scoped_string & scopedstr, const class ::time& timezone = {});
165
166 ::i32 SWN(::i32 y,::i32 m,::i32 d);
167 ::i32 DP(::i32 y,::i32 m);
168 ::i32 ML(::i32 y,::i32 m);
169 ::i32 LEAP(::i32 y);
170 ::i32 dayofweek(::i32 y,::i32 m,::i32 d); /* 0 = Sunday */
171 ::i32 SDOW(::i32 y,::i32 m,::i32 d);
172 ::i32 DOW(::i32 y,::i32 m,::i32 d);
173 ::i32 getDayOfWeek(::i32 month,::i32 day,::i32 year,::i32 CalendarSystem);
174 ::i32 ISO_WN(::i32 y,::i32 m,::i32 d);
175
176 virtual string to_string(const ::text::context* pcontext, const ::datetime::result& result, const class ::time& timeshift = {});
177
178 virtual result span_parse_time(const ::text::context* pcontext, const ::scoped_string & scopedstr, const class ::time& timeshift = {});
179
180 virtual result parse_time(const ::text::context* pcontext, const ::scoped_string & scopedstr, ::i32& iPath, ::i32& iPathCount, const class ::time& timeshift = {});
181
182 string friend_time(const ::text::context * pcontext,::earth::time timeNow,::earth::time time, const class ::time& timeshift = {});
183
184 virtual string _001FriendTime(const ::text::context* pcontext, const ::earth::time& timeNow, const ::earth::time& time, const class ::time& timeshift = {});
185
186 virtual ::string friendly_elapsed(const class ::time& time);
187
188 ::posix_time parse(const ::scoped_string & scopedstr);
189
190 void parse_text(const ::scoped_string & scopedstr, ::property_set & set);
191 ::earth::time parse_text(const ::scoped_string & scopedstr);
192
193
194 //string date_time_text(const ::earth::time& time, const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_TIME_FORMAT, const class ::time& timeshift = {});
195 //string date_time_text(const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_TIME_FORMAT, const class ::time& timeshift = {});
196 //string date_time_text_for_file(const class ::time& timeshift = {}, const ::earth::time& time = ::earth::time::now());
197
198
199
200 //string local_get_date_time(const ::earth::time & time, const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_TIME_FORMAT);
201 //string local_get_date_time(const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_TIME_FORMAT);
202 //string local_get_date_time_for_file();
203
204
205 string get_date_time_for_file_with_no_spaces(const class ::time& timeshift = {}, const ::earth::time& time = ::earth::time::now());
206 //string local_get_date_time_for_file_with_no_spaces();
207
208
209 virtual string format(const ::scoped_string& strFormat, const ::earth::time& time = ::time::now(), const class ::time& timeshift = {});
210 //inline string format(const ::scoped_string& strFormat, const class ::time& timeshift = {}) { return format(::time::now(), strFormat, timeshift); }
211
212
213 inline string date_time_text(const ::earth::time& time, const class ::time& timeshift = {}) { return format(INTERNATIONAL_DATE_TIME_FORMAT, time, timeshift); }
214 inline string date_time_text(const class ::time & timeshift = {}) { return date_time_text(::time::now(), timeshift); }
215 inline string date_time_text_for_file(const ::earth::time& time, const class ::time& timeshift = {}) { return format(INTERNATIONAL_DATE_TIME_FORMAT_FOR_FILE, time, timeshift); }
216 inline string date_time_text_for_file(const class ::time& timeshift = {}) { return date_time_text_for_file(::time::now(), timeshift); }
217 inline string date_time_text_for_file_with_no_spaces(const ::earth::time& time, const class ::time& timeshift = {}) { return format(INTERNATIONAL_DATE_TIME_FORMAT_FOR_FILE_WITH_NO_SPACES, time, timeshift); }
218 inline string date_time_text_for_file_with_no_spaces(const class ::time& timeshift = {}) { return date_time_text_for_file_with_no_spaces(::time::now(), timeshift); }
219
220
221 inline ::string date_text(const ::earth::time& time, const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_FORMAT, const class ::time& timeshift = {}) { return format(scopedstrFormat, time, timeshift); }
222 inline ::string date_text(const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_FORMAT, const class ::time& timeshift = {}) { return format(scopedstrFormat, ::time::now(), timeshift); }
223 inline ::string date_text_for_file(const class ::time& timeshift = {}, const ::earth::time& time = ::earth::time::now()) { return format(INTERNATIONAL_DATE_FORMAT_FOR_FILE, time, timeshift); }
224
225
226 //inline string local_get(const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_TIME_FORMAT) { return local_get_date_time(strFormat); }
227 //inline string local_get(const ::earth::time & time, const ::scoped_string & scopedstrFormat = INTERNATIONAL_DATE_TIME_FORMAT) { return local_get_date_time(time, strFormat); }
228
229
230 //inline string utc() { return utc_get(); }
231 //inline string utc(const ::earth::time & time) { return utc_get(time); }
232 //inline string local() { return local_get(); }
233 //inline string local(const ::earth::time & time) { return local_get(time); }
234
235
236virtual ::string elapsed_nanoseconds_text(::i64 iNanoseconds);
237
238
239virtual ::string elapsed_time_text(const class ::time & time);
240
241
242 };
243
244
245} // namespace apex
246
247
248
249CLASS_DECL_ACME ::earth::time earth_time_from_international_string(const ::scoped_string& scopedstrTime);
void initialize(::particle *pparticle) override
Definition datetime.cpp:61
Definition result.h:9
Definition day.h:8
Definition earth_time.h:33
Definition particle.h:95
Definition department.h:13
Definition aaa_time.h:13
Definition posix_time.h:8