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
|
#ifndef slic3r_Utils_Time_hpp_
#define slic3r_Utils_Time_hpp_
#include <string>
#include <ctime>
namespace Slic3r {
namespace Utils {
// Should be thread safe.
time_t get_current_time_utc();
enum class TimeZone { local, utc };
enum class TimeFormat { gcode, iso8601Z };
// time_t to string functions...
std::string time2str(const time_t &t, TimeZone zone, TimeFormat fmt);
inline std::string time2str(TimeZone zone, TimeFormat fmt)
{
return time2str(get_current_time_utc(), zone, fmt);
}
inline std::string utc_timestamp(time_t t)
{
return time2str(t, TimeZone::utc, TimeFormat::gcode);
}
inline std::string utc_timestamp()
{
return utc_timestamp(get_current_time_utc());
}
// String to time_t function. Returns time_t(-1) if fails to parse the input.
time_t str2time(const std::string &str, TimeZone zone, TimeFormat fmt);
// /////////////////////////////////////////////////////////////////////////////
// Utilities to convert an UTC time_t to/from an ISO8601 time format,
// useful for putting timestamps into file and directory names.
// Returns (time_t)-1 on error.
// Use these functions to convert safely to and from the ISO8601 format on
// all platforms
inline std::string iso_utc_timestamp(time_t t)
{
return time2str(t, TimeZone::utc, TimeFormat::iso8601Z);
}
inline std::string iso_utc_timestamp()
{
return iso_utc_timestamp(get_current_time_utc());
}
inline time_t parse_iso_utc_timestamp(const std::string &str)
{
return str2time(str, TimeZone::utc, TimeFormat::iso8601Z);
}
// /////////////////////////////////////////////////////////////////////////////
} // namespace Utils
} // namespace Slic3r
#endif /* slic3r_Utils_Time_hpp_ */
|