Audacity 3.2.0
DateTimeConversions.cpp
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file DateTimeConversions.cpp
6 @brief Define functions to work with date and time string representations.
7
8 Dmitry Vedenko
9 **********************************************************************/
10
11#include "DateTimeConversions.h"
12
13#include <wx/datetime.h>
14
15#include "CodeConversions.h"
16
17namespace audacity
18{
19
20bool ParseRFC822Date (const std::string& dateString, SystemTime* time)
21{
22 wxDateTime dt;
23 wxString::const_iterator end;
24
25 if (!dt.ParseRfc822Date (dateString, &end))
26 return false;
27
28 if (time != nullptr)
29 *time = std::chrono::system_clock::from_time_t (dt.GetTicks ());
30
31 return true;
32}
33
34bool ParseISO8601Date (const std::string& dateString, SystemTime* time)
35{
36 wxDateTime dt;
37
38 wxString::const_iterator end;
39 const wxString fmt = wxS("%Y%m%dT%H%M%SZ");
40
41 if (!dt.ParseFormat(dateString, fmt, &end))
42 return false;
43
44 if (time != nullptr)
45 *time = std::chrono::system_clock::from_time_t (dt.GetTicks ());
46
47 return true;
48}
49
50std::string SerializeRFC822Date (SystemTime timePoint)
51{
52 const wxDateTime dt (
53 time_t (std::chrono::duration_cast<std::chrono::seconds> (
54 timePoint.time_since_epoch ()
55 ).count ()));
56
57 return ToUTF8 (dt.Format("%a, %d %b %Y %H:%M:%S %z"));
58}
59
60}
Declare functions to perform UTF-8 to std::wstring conversions.
Declare functions to work with date and time string representations.
std::string ToUTF8(const std::wstring &wstr)
bool ParseRFC822Date(const std::string &dateString, SystemTime *time)
bool ParseISO8601Date(const std::string &dateString, SystemTime *time)
std::string SerializeRFC822Date(SystemTime timePoint)
std::chrono::system_clock::time_point SystemTime
const char * end(const char *str) noexcept
Definition: StringUtils.h:106