1 |
20 |
jlechner |
// std::time_get, std::time_put implementation, generic version -*- C++ -*-
|
2 |
|
|
|
3 |
|
|
// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
|
4 |
|
|
//
|
5 |
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
6 |
|
|
// software; you can redistribute it and/or modify it under the
|
7 |
|
|
// terms of the GNU General Public License as published by the
|
8 |
|
|
// Free Software Foundation; either version 2, or (at your option)
|
9 |
|
|
// any later version.
|
10 |
|
|
|
11 |
|
|
// This library is distributed in the hope that it will be useful,
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
|
|
// GNU General Public License for more details.
|
15 |
|
|
|
16 |
|
|
// You should have received a copy of the GNU General Public License along
|
17 |
|
|
// with this library; see the file COPYING. If not, write to the Free
|
18 |
|
|
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
19 |
|
|
// USA.
|
20 |
|
|
|
21 |
|
|
// As a special exception, you may use this file as part of a free software
|
22 |
|
|
// library without restriction. Specifically, if other files instantiate
|
23 |
|
|
// templates or use macros or inline functions from this file, or you compile
|
24 |
|
|
// this file and link it with other files to produce an executable, this
|
25 |
|
|
// file does not by itself cause the resulting executable to be covered by
|
26 |
|
|
// the GNU General Public License. This exception does not however
|
27 |
|
|
// invalidate any other reasons why the executable file might be covered by
|
28 |
|
|
// the GNU General Public License.
|
29 |
|
|
|
30 |
|
|
//
|
31 |
|
|
// ISO C++ 14882: 22.2.5.1.2 - time_get virtual functions
|
32 |
|
|
// ISO C++ 14882: 22.2.5.3.2 - time_put virtual functions
|
33 |
|
|
//
|
34 |
|
|
|
35 |
|
|
// Written by Benjamin Kosnik <bkoz@redhat.com>
|
36 |
|
|
|
37 |
|
|
#include <locale>
|
38 |
|
|
|
39 |
|
|
namespace std
|
40 |
|
|
{
|
41 |
|
|
template<>
|
42 |
|
|
void
|
43 |
|
|
__timepunct<char>::
|
44 |
|
|
_M_put(char* __s, size_t __maxlen, const char* __format,
|
45 |
|
|
const tm* __tm) const
|
46 |
|
|
{
|
47 |
|
|
char* __old = strdup(setlocale(LC_ALL, NULL));
|
48 |
|
|
setlocale(LC_ALL, _M_name_timepunct);
|
49 |
|
|
const size_t __len = strftime(__s, __maxlen, __format, __tm);
|
50 |
|
|
setlocale(LC_ALL, __old);
|
51 |
|
|
free(__old);
|
52 |
|
|
// Make sure __s is null terminated.
|
53 |
|
|
if (__len == 0)
|
54 |
|
|
__s[0] = '\0';
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
template<>
|
58 |
|
|
void
|
59 |
|
|
__timepunct<char>::_M_initialize_timepunct(__c_locale)
|
60 |
|
|
{
|
61 |
|
|
// "C" locale.
|
62 |
|
|
if (!_M_data)
|
63 |
|
|
_M_data = new __timepunct_cache<char>;
|
64 |
|
|
|
65 |
|
|
_M_data->_M_date_format = "%m/%d/%y";
|
66 |
|
|
_M_data->_M_date_era_format = "%m/%d/%y";
|
67 |
|
|
_M_data->_M_time_format = "%H:%M:%S";
|
68 |
|
|
_M_data->_M_time_era_format = "%H:%M:%S";
|
69 |
|
|
_M_data->_M_date_time_format = "";
|
70 |
|
|
_M_data->_M_date_time_era_format = "";
|
71 |
|
|
_M_data->_M_am = "AM";
|
72 |
|
|
_M_data->_M_pm = "PM";
|
73 |
|
|
_M_data->_M_am_pm_format = "";
|
74 |
|
|
|
75 |
|
|
// Day names, starting with "C"'s Sunday.
|
76 |
|
|
_M_data->_M_day1 = "Sunday";
|
77 |
|
|
_M_data->_M_day2 = "Monday";
|
78 |
|
|
_M_data->_M_day3 = "Tuesday";
|
79 |
|
|
_M_data->_M_day4 = "Wednesday";
|
80 |
|
|
_M_data->_M_day5 = "Thursday";
|
81 |
|
|
_M_data->_M_day6 = "Friday";
|
82 |
|
|
_M_data->_M_day7 = "Saturday";
|
83 |
|
|
|
84 |
|
|
// Abbreviated day names, starting with "C"'s Sun.
|
85 |
|
|
_M_data->_M_aday1 = "Sun";
|
86 |
|
|
_M_data->_M_aday2 = "Mon";
|
87 |
|
|
_M_data->_M_aday3 = "Tue";
|
88 |
|
|
_M_data->_M_aday4 = "Wed";
|
89 |
|
|
_M_data->_M_aday5 = "Thu";
|
90 |
|
|
_M_data->_M_aday6 = "Fri";
|
91 |
|
|
_M_data->_M_aday7 = "Sat";
|
92 |
|
|
|
93 |
|
|
// Month names, starting with "C"'s January.
|
94 |
|
|
_M_data->_M_month01 = "January";
|
95 |
|
|
_M_data->_M_month02 = "February";
|
96 |
|
|
_M_data->_M_month03 = "March";
|
97 |
|
|
_M_data->_M_month04 = "April";
|
98 |
|
|
_M_data->_M_month05 = "May";
|
99 |
|
|
_M_data->_M_month06 = "June";
|
100 |
|
|
_M_data->_M_month07 = "July";
|
101 |
|
|
_M_data->_M_month08 = "August";
|
102 |
|
|
_M_data->_M_month09 = "September";
|
103 |
|
|
_M_data->_M_month10 = "October";
|
104 |
|
|
_M_data->_M_month11 = "November";
|
105 |
|
|
_M_data->_M_month12 = "December";
|
106 |
|
|
|
107 |
|
|
// Abbreviated month names, starting with "C"'s Jan.
|
108 |
|
|
_M_data->_M_amonth01 = "Jan";
|
109 |
|
|
_M_data->_M_amonth02 = "Feb";
|
110 |
|
|
_M_data->_M_amonth03 = "Mar";
|
111 |
|
|
_M_data->_M_amonth04 = "Apr";
|
112 |
|
|
_M_data->_M_amonth05 = "May";
|
113 |
|
|
_M_data->_M_amonth06 = "Jun";
|
114 |
|
|
_M_data->_M_amonth07 = "Jul";
|
115 |
|
|
_M_data->_M_amonth08 = "Aug";
|
116 |
|
|
_M_data->_M_amonth09 = "Sep";
|
117 |
|
|
_M_data->_M_amonth10 = "Oct";
|
118 |
|
|
_M_data->_M_amonth11 = "Nov";
|
119 |
|
|
_M_data->_M_amonth12 = "Dec";
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
#ifdef _GLIBCXX_USE_WCHAR_T
|
123 |
|
|
template<>
|
124 |
|
|
void
|
125 |
|
|
__timepunct<wchar_t>::
|
126 |
|
|
_M_put(wchar_t* __s, size_t __maxlen, const wchar_t* __format,
|
127 |
|
|
const tm* __tm) const
|
128 |
|
|
{
|
129 |
|
|
char* __old = strdup(setlocale(LC_ALL, NULL));
|
130 |
|
|
setlocale(LC_ALL, _M_name_timepunct);
|
131 |
|
|
const size_t __len = wcsftime(__s, __maxlen, __format, __tm);
|
132 |
|
|
setlocale(LC_ALL, __old);
|
133 |
|
|
free(__old);
|
134 |
|
|
// Make sure __s is null terminated.
|
135 |
|
|
if (__len == 0)
|
136 |
|
|
__s[0] = L'\0';
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
template<>
|
140 |
|
|
void
|
141 |
|
|
__timepunct<wchar_t>::_M_initialize_timepunct(__c_locale)
|
142 |
|
|
{
|
143 |
|
|
// "C" locale.
|
144 |
|
|
if (!_M_data)
|
145 |
|
|
_M_data = new __timepunct_cache<wchar_t>;
|
146 |
|
|
|
147 |
|
|
_M_data->_M_date_format = L"%m/%d/%y";
|
148 |
|
|
_M_data->_M_date_era_format = L"%m/%d/%y";
|
149 |
|
|
_M_data->_M_time_format = L"%H:%M:%S";
|
150 |
|
|
_M_data->_M_time_era_format = L"%H:%M:%S";
|
151 |
|
|
_M_data->_M_date_time_format = L"";
|
152 |
|
|
_M_data->_M_date_time_era_format = L"";
|
153 |
|
|
_M_data->_M_am = L"AM";
|
154 |
|
|
_M_data->_M_pm = L"PM";
|
155 |
|
|
_M_data->_M_am_pm_format = L"";
|
156 |
|
|
|
157 |
|
|
// Day names, starting with "C"'s Sunday.
|
158 |
|
|
_M_data->_M_day1 = L"Sunday";
|
159 |
|
|
_M_data->_M_day2 = L"Monday";
|
160 |
|
|
_M_data->_M_day3 = L"Tuesday";
|
161 |
|
|
_M_data->_M_day4 = L"Wednesday";
|
162 |
|
|
_M_data->_M_day5 = L"Thursday";
|
163 |
|
|
_M_data->_M_day6 = L"Friday";
|
164 |
|
|
_M_data->_M_day7 = L"Saturday";
|
165 |
|
|
|
166 |
|
|
// Abbreviated day names, starting with "C"'s Sun.
|
167 |
|
|
_M_data->_M_aday1 = L"Sun";
|
168 |
|
|
_M_data->_M_aday2 = L"Mon";
|
169 |
|
|
_M_data->_M_aday3 = L"Tue";
|
170 |
|
|
_M_data->_M_aday4 = L"Wed";
|
171 |
|
|
_M_data->_M_aday5 = L"Thu";
|
172 |
|
|
_M_data->_M_aday6 = L"Fri";
|
173 |
|
|
_M_data->_M_aday7 = L"Sat";
|
174 |
|
|
|
175 |
|
|
// Month names, starting with "C"'s January.
|
176 |
|
|
_M_data->_M_month01 = L"January";
|
177 |
|
|
_M_data->_M_month02 = L"February";
|
178 |
|
|
_M_data->_M_month03 = L"March";
|
179 |
|
|
_M_data->_M_month04 = L"April";
|
180 |
|
|
_M_data->_M_month05 = L"May";
|
181 |
|
|
_M_data->_M_month06 = L"June";
|
182 |
|
|
_M_data->_M_month07 = L"July";
|
183 |
|
|
_M_data->_M_month08 = L"August";
|
184 |
|
|
_M_data->_M_month09 = L"September";
|
185 |
|
|
_M_data->_M_month10 = L"October";
|
186 |
|
|
_M_data->_M_month11 = L"November";
|
187 |
|
|
_M_data->_M_month12 = L"December";
|
188 |
|
|
|
189 |
|
|
// Abbreviated month names, starting with "C"'s Jan.
|
190 |
|
|
_M_data->_M_amonth01 = L"Jan";
|
191 |
|
|
_M_data->_M_amonth02 = L"Feb";
|
192 |
|
|
_M_data->_M_amonth03 = L"Mar";
|
193 |
|
|
_M_data->_M_amonth04 = L"Apr";
|
194 |
|
|
_M_data->_M_amonth05 = L"May";
|
195 |
|
|
_M_data->_M_amonth06 = L"Jun";
|
196 |
|
|
_M_data->_M_amonth07 = L"Jul";
|
197 |
|
|
_M_data->_M_amonth08 = L"Aug";
|
198 |
|
|
_M_data->_M_amonth09 = L"Sep";
|
199 |
|
|
_M_data->_M_amonth10 = L"Oct";
|
200 |
|
|
_M_data->_M_amonth11 = L"Nov";
|
201 |
|
|
_M_data->_M_amonth12 = L"Dec";
|
202 |
|
|
}
|
203 |
|
|
#endif
|
204 |
|
|
}
|