File: time.cc

package info (click to toggle)
natlog 3.01.00-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,912 kB
  • sloc: cpp: 3,691; fortran: 201; sh: 133; ansic: 123; makefile: 110
file content (41 lines) | stat: -rw-r--r-- 864 bytes parent folder | download | duplicates (5)
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
#include "showseconds.ih"

namespace
{
    void insertTime(DateTime::TimeType type, 
                    std::ostream &out, size_t seconds)
    {
        
        DateTime dt(static_cast<time_t>(seconds), type);
        ostringstream os;
        os << dt;
            // E.g., 'Sun Nov 2 13:29:11 2008'
            //        01234             56789
        out << os.str().substr(4, os.str().length() - 9);
    }
}

void ShowSeconds::rawTime(ostream &out, size_t seconds)
{
    out << seconds;
}

void ShowSeconds::utcTime(ostream &out, size_t seconds)
{
    insertTime(DateTime::UTC, out, seconds);
}

void ShowSeconds::localTime(ostream &out, size_t seconds)
{
    insertTime(DateTime::LOCALTIME, out, seconds);
}

string ShowSeconds::now()
{
    ostringstream out;

    out << ShowSeconds{ static_cast<size_t>(time(0)) } << ":000000";

    return out.str();
}