Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Time.hpp « libslic3r « src - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b314e47f728708cbc5326013b01d626c2a42917b (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
#ifndef slic3r_Utils_Time_hpp_
#define slic3r_Utils_Time_hpp_

#include <string>
#include <ctime>

namespace Slic3r {
namespace Utils {

// 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.
time_t parse_time_ISO8601Z(const std::string &s);
std::string format_time_ISO8601Z(time_t time);

// Format the date and time from an UTC time according to the active locales and a local time zone.
// TODO: make sure time2str is a suitable replacement
std::string format_local_date_time(time_t time);

// There is no gmtime() on windows.
time_t get_current_time_utc();

const constexpr char *const SLIC3R_TIME_FMT = "%Y-%m-%d at %T";

enum class TimeZone { local, utc };

std::string time2str(const time_t &t, TimeZone zone, const char *fmt = SLIC3R_TIME_FMT);

inline std::string current_time2str(TimeZone zone, const char *fmt = SLIC3R_TIME_FMT)
{
    return time2str(get_current_time_utc(), zone, fmt);
}

inline std::string current_local_time2str(const char * fmt = SLIC3R_TIME_FMT)
{
    return current_time2str(TimeZone::local, fmt);    
}

inline std::string current_utc_time2str(const char * fmt = SLIC3R_TIME_FMT)
{
    return current_time2str(TimeZone::utc, fmt);
}

}; // namespace Utils
}; // namespace Slic3r

#endif /* slic3r_Utils_Time_hpp_ */