File: DateTimeConversions.cpp

package info (click to toggle)
audacity 3.2.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 106,704 kB
  • sloc: cpp: 277,038; ansic: 73,623; lisp: 7,761; python: 3,305; sh: 2,715; perl: 821; xml: 275; makefile: 119
file content (44 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download
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
/*!********************************************************************

 Audacity: A Digital Audio Editor

 @file DateTimeConversions.cpp
 @brief Define functions to work with date and time string representations.

 Dmitry Vedenko
 **********************************************************************/

#include "DateTimeConversions.h"

#include <wx/datetime.h>

#include "CodeConversions.h"

namespace audacity
{

bool ParseRFC822Date (const std::string& dateString, SystemTime* time)
{
    wxDateTime dt;
    wxString::const_iterator end;

    if (!dt.ParseRfc822Date (dateString, &end))
        return false;

    if (time != nullptr)
        *time = std::chrono::system_clock::from_time_t (dt.GetTicks ());

    return true;
}

std::string SerializeRFC822Date (SystemTime timePoint)
{
    const wxDateTime dt (
            time_t (std::chrono::duration_cast<std::chrono::seconds> (
                    timePoint.time_since_epoch ()
            ).count ()));

    return ToUTF8 (dt.Format("%a, %d %b %Y %H:%M:%S %z"));
}

}