acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
file_time.h
1#pragma once
2
3
4#include "file_time_span.h"
5
6
7struct file_time_t {};
8
9
10class CLASS_DECL_ACME file_time
11{
12public:
13
14
15 // Microseconds between 1601-01-01 00:00:00 UTC and 1970-01-01 00:00:00 UTC
16 inline static constexpr ::u64 EPOCH_DIFFERENCE_100NS = 116444736000000000ull;
17
18
19 // Contains a 64-bit value representing the number
20 // of 100-nanosecond intervals since January 1, 1601 (UTC).
21 ::u64 m_uFileTime;
22
23
24 file_time() noexcept { m_uFileTime = 0; }
25 file_time(file_time_t, ::u64 uFileTime) noexcept { m_uFileTime = uFileTime; }
26 explicit file_time(const system_time & systemtime);
27 explicit file_time(const ::posix_time & time);
28 explicit file_time(const class ::time & time);
29 explicit file_time(const ::earth::gregorian_time & gregoriantime);
30 // ystem_time_as_file_time();
31 //file_time(local_const ::file_time & filetime);
32 //file_time(const ::earth::time & time);
33 file_time(now_t);
34
35 static file_time now() noexcept;
36
37
38 //explicit operator file_time_t &() { return m_filetime; }
39 //explicit operator file_time_t () const { return m_filetime; }
40
41
42 file_time& operator +=(file_time_span span) noexcept;
43 file_time& operator-=(file_time_span span) noexcept;
44
45 file_time operator +(file_time_span span) const noexcept;
46 file_time operator-(file_time_span span) const noexcept;
47 file_time_span operator-(file_time ft) const noexcept;
48
49 bool operator==(file_time ft) const noexcept;
50 std::strong_ordering operator<=>(file_time ft) const noexcept;
51 //bool operator<(file_time ft) const noexcept;
52 //bool operator>(file_time ft) const noexcept;
53 //bool operator<=(file_time ft) const noexcept;
54 //bool operator>=(file_time ft) const noexcept;
55
56 ::u64 get_file_time() const noexcept;
57 void set_file_time(::u64 nTime) noexcept;
58
59
60
61 //file_time UTCToLocal() const noexcept;
62 //file_time LocalToUTC() const noexcept;
63
64 //static const file_time_t Millisecond;
65 //static const file_time_t Second;
66 //static const file_time_t Minute;
67 //static const file_time_t Hour;
68 //static const file_time_t Day;
69 //static const file_time_t Week;
70
71};
72
73
74// Used only if these strings could not be found in resources.
75extern CLASS_DECL_ACME const_char_pointer const szInvalidDateTime;
76extern CLASS_DECL_ACME const_char_pointer const szInvalidDateTimeSpan;
77
78const ::i32 maxTimeBufferSize = 128;
79const long maxDaysInSpan = 3615897L;
80
81
82//CLASS_DECL_ACME file_time_t get_file_time_now();
83
84
85struct CLASS_DECL_ACME file_time_set
86{
87
88
89 file_time m_filetimeCreation;
90 file_time m_filetimeModified;
91 file_time m_filetimeAccess; // Not used at Windows?
92
93
94 file_time_set() {}
95
96
97 bool operator == (const file_time_set & file_timeset) const
98 {
99 return
100 &file_timeset == this ||
101 (
102 m_filetimeCreation == file_timeset.m_filetimeCreation
103 && m_filetimeModified == file_timeset.m_filetimeModified
104 && m_filetimeAccess == file_timeset.m_filetimeAccess
105 );
106 }
107
108
109
110 bool modified_timeout(const file_time & current, ::i32 iSeconds) const
111 {
112
113 if ((current - m_filetimeModified).m_iFileTimeSpan > (iSeconds * 10'000'000))
114 {
115
116 return true;
117
118 }
119
120 return false;
121
122 }
123
124
125 bool modified_timeout(::i32 iSeconds) const;
126
127};
128
129
130namespace earth
131{
132
133 class time;
134 class zone_time;
135
136} // namespace earth
137
138
139CLASS_DECL_ACME bool file_modified_timeout(const ::file::path & path, ::i32 iSeconds);
140
141
142CLASS_DECL_ACME void get_file_time_set(const ::file::path & path, file_time_set & time);
143
144CLASS_DECL_ACME void get_file_time_set(const ::file::path & path, file_time & creation, file_time & modified);
145
146CLASS_DECL_ACME void set_modified_file_time(const ::file::path & path, const class ::time & time);
147
148CLASS_DECL_ACME void set_modified_file_time(const ::file::path & path, const file_time & modified);
149
150inline file_time_set get_file_time_set(const ::file::path & path)
151{
152
153 file_time_set filetimeset;
154
155 try
156 {
157
158 get_file_time_set(path, filetimeset);
159
160 }
161 catch (...)
162 {
163
164 return {};
165
166 }
167
168 return filetimeset;
169
170}
171
172
173//CLASS_DECL_ACME file_time __file_time(const ::earth::time & time);
174
175
176//posix_time __time(const file_time & file_time);
177
178
179
180CLASS_DECL_ACME file_time as_local_file_time(const ::file_time & filetime);
181
182
183
Definition file_time_span.h:8
Definition file_time.h:11
Definition system_time.h:8
Definition aaa_time.h:13
Definition file_time.h:86
Definition file_time.h:7
Definition _structures.h:48