File: puttime.yo

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (186 lines) | stat: -rw-r--r-- 8,302 bytes parent folder | download | duplicates (4)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
The manipulator hi(put_time) tt(std::put_time(std::tm const *specs, char const
*fmt)) can be used to insert time specifications into tt(std::ostream)
objects.

Time specifications are provided in tt(std::tm) objects, and the way the time
should be displayed is defined by the emi(format string) tt(fmt).

Starting with a tt(chrono::time_point) the following steps must be performed
to insert the time point's time into a tt(std::ostream):
    itemization(
    it() Obtain a tt(time_point) (e.g.: tt(system_clock{}.now()));

    it() Pass the time point to the clock's tt(to_time_t) function, saving the
returned tt(time_t) value:
        verb(time_t secs = system_clock::to_time_t( system_clock{}.now() );)

it() Pass tt(sec's) address to either hi(localtime)tt(std::localtime) or
hi(gmtime)tt(std::gmtime). These functions return tt(std::tm) structs
containing the required time components expressed in, respectively, the
computer's local time or GMT;

    it() Pass the return value of either tt(localtime) or tt(gmtime) together
with a format string (e.g., tt("%c")) to tt(put_time), inserting it into an
tt(std::ostream):
        verb(                // displays, e.g., Mon Nov  4 21:34:59 2019
time_t secs = system_clock::to_time_t( system_clock{}.now() );
std::cout << std::put_time(std::localtime(&secs), "%c") << '\n';)

)

A simple function returning tt(put_time's) return value and expecting a
tt(time_point) and format string can be defined which handles the above two
statements. E.g., (omitting the tt(std::) and tt(std::chrono::) specifications
for brevity):
        verb(    auto localTime(time_point<system_clock> const &tp, char const *fmt)
    {
        time_t secs = system_clock::to_time_t( tp );
        return put_time(localtime(&secs), fmt);
    }
                // used as:
    cout << localTime(system_clock{}.now(), "%c") << '\n';)

Many more format specifiers are recognized by tt(put_time).  Specifiers start
with tt(%). To display a percent character as part of the format string write
it twice: tt(%%). In addition to the standard escape sequences, tt(%n) can be
used instead of tt(\n), and tt(%t) can be used instead of tt(\t).

centertbl(lllll)(\
    tline()()\
    tr(xcell(5)(Year specifiers))
    tr(cell(Specifier)cell()cell(Meaning)cell()tlc()(std::tm field(s)))
    tline()()\
    rowthree(Y)(year as a 4 digit decimal number)(tm_year)
    rowthree(EY)(year in an alternative representation)(tm_year)
    rowthree(y)(last 2 digits of year as a decimal number
                (range [00,99]))(tm_year)
    rowthree(Oy)(last 2 digits of year using an alternative numeric
                system)(tm_year)
    rowthree(Ey)(year as offset from locale's alternative calendar
                period %EC (locale-dependent))(tm_year)
    rowthree(C)(first 2 digits of year as a decimal number
                (range [00,99]))(tm_year)
    rowthree(EC)(name of the base year (period) in the locale's
                alternative representation)(tm_year)
    rowthree(G)(ISO 8601 week-based year, i.e. the year that contains
                the specified week)(tm_year,nl() tm_wday,nl() tm_yday)
    rowthree(g)(last 2 digits of ISO 8601 week-based year
                (range [00,99]))(tm_year,nl() tm_wday,nl() tm_yday)
    tline()()\
)

centertbl(lllll)(\
    tline()()\
    tr(xcell(5)(Month specifiers))
    tr(cell(Specifier)cell()cell(Meaning)cell()tlc()(std::tm field(s)))
    tline()()\
    rowthree(b)(abbreviated month name, e.g. Oct)(tm_mon)\
    rowthree(m)(month as a decimal number (range [01,12]))(tm_mon)\
    rowthree(Om)(month using an alternative numeric system)(tm_mon)\
    tline()()\
)

centertbl(lllll)(\
    tline()()\
    tr(xcell(5)(Week specifiers))
    tr(cell(Specifier)cell()cell(Meaning)cell()tlc()(std::tm field(s)))
    tline()()\
    rowthree(U)(week of the year as a decimal number (Sunday is the first day
            of the week) (range [00,53]))(tm_year,nl()tm_wday,nl()tm_yday)
    rowthree(OU)(week of the year, as by %U, using an alternative numeric
            system)(tm_year,nl() tm_wday,nl() tm_yday)
    rowthree(W)(week of the year as a decimal number (Monday is the first day
            of the week) (range [00,53]))(tm_year,nl() tm_wday,nl() tm_yday)
    rowthree(OW)(week of the year, as by %W, using an alternative numeric
            system)(tm_year,nl() tm_wday,nl() tm_yday)
    rowthree(V)(ISO 8601 week of the year (range [01,53]))
            (tm_year,nl() tm_wday,nl() tm_yday)
    rowthree(OV)(week of the year, as by %V, using an alternative numeric
            system)(tm_year,nl() tm_wday,nl() tm_yday)
    tline()()\
)

centertbl(lllll)(\
    tline()()\
    tr(xcell(5)(Day of the year/month specifiers))
    tr(cell(Specifier)cell()cell(Meaning)cell()tlc()(std::tm field(s)))
    tline()()\
    rowthree(j)(day of the year as a decimal number (range
                [001,366]))(tm_yday)
    rowthree(d)(day of the month as a decimal number (range [01,31]))(tm_mday)
    rowthree(Od)(zero-based day of the month using an alternative numeric
                system)(tm_mday)
    rowthree(e)(day of the month as a decimal number (range [1,31]))(tm_mday)
    rowthree(Oe)(one-based day of the month using an alternative numeric
            system)(tm_mday)
    tline()()\
)

centertbl(lllll)(\
    tline()()\
    tr(xcell(5)(Day of the week specifiers))
    tr(cell(Specifier)cell()cell(Meaning)cell()tlc()(std::tm field(s)))
    tline()()\
    rowthree(a)(abbreviated weekday name, e.g. Fri)(tm_wday)
    rowthree(A)(full weekday name, e.g. Friday)(tm_wday)
    rowthree(w)(weekday as a decimal number, where Sunday is 0 (range
                [0-6]))(tm_wday)
    rowthree(Ow)(weekday, where Sunday is 0, using an alternative numeric
                system)(tm_wday)
    rowthree(u)(weekday as a decimal number, where Monday is 1 (ISO 8601
                format) (range [1-7]))(tm_wday)
    rowthree(Ou)(weekday, where Monday is 1, using an alternative numeric
                system)(tm_wday)
    tline()()\
)

centertbl(lllll)(\
    tline()()\
    tr(xcell(5)(Hour, minute, second  specifiers))\
    tr(cell(Specifier)cell()cell(Meaning)cell()tlc()(std::tm field(s)))\
    tline()()\
    rowthree(H)(hour as a decimal number, 24 hour clock (range
                [00-23]))(tm_hour)\
    rowthree(OH)(hour from 24-hour clock using an alternative numeric
                system)(tm_hour)\
    rowthree(I)(hour as a decimal number, 12 hour clock (range
                [01,12]))(tm_hour)\
    rowthree(OI)(hour from 12-hour clock using the alternative numeric
                system)(tm_hour)\
    rowthree(M)(minute as a decimal number (range [00,59]))(tm_min)\
    rowthree(OM)(minute using an alternative numeric system)(tm_min)\
    rowthree(S)(second as a decimal number (range [00,60]))(tm_sec)\
    rowthree(OS)(second using an alternative numeric system)(tm_sec)\
    tline()()\
)

centertbl(lllll)(\
    tline()()\
    tr(xcell(5)(Additional specifiers))\
    tr(cell(Specifier)cell()cell(Meaning)cell()tlc()(std::tm field(s)))\
    tline()()\
    rowthree(c)(standard date and time string, e.g. Sun Oct 17 04:41:13
                2010)(all)\
    rowthree(Ec)(alternative date and time string)(all)\
    rowthree(x)(localized date representation)(all)\
    rowthree(Ex)(alternative date representation)(all)\
    rowthree(X)(localized time representation)(all)\
    rowthree(EX)(alternative time representation)(all)\
    rowthree(D)(equivalent to tt("%m/%d/%y"))(tm_mon,nl() tm_mday,nl()
                tm_year)\
    rowthree(F)(equivalent to tt("%Y-%m-%d") (the ISO 8601 date
                format))(tm_mon,nl() tm_mday,nl() tm_year)\
    rowthree(r)(localized 12-hour clock time)(tm_hour,nl() tm_min,nl()
                tm_sec)\
    rowthree(R)(equivalent to tt("%H:%M"))(tm_hour,nl() tm_min)\

    rowthree(T)(equivalent to tt("%H:%M:%S") (the ISO 8601 time
                format))(tm_hour,nl() tm_min,nl() tm_sec)\
    rowthree(p)(localized a.m. or p.m.)(tm_hour)\
    rowthree(z)(offset from UTC in the ISO 8601 format (e.g. -0430;nl() no
                characters if time zone information is not
                available))(tm_isdst)\
    rowthree(Z)(time zone name or abbreviation+nl()(no characters if time zone
                information is not available))(tm_isdst)\
    tline()()\
)