]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/config/locale/generic/time_members.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / config / locale / generic / time_members.cc
CommitLineData
1c26d8fd 1// std::time_get, std::time_put implementation, generic version -*- C++ -*-
1ab65677 2
99dee823 3// Copyright (C) 2001-2021 Free Software Foundation, Inc.
1ab65677
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
1ab65677
BK
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
748086b7
JJ
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
1ab65677
BK
24
25//
26// ISO C++ 14882: 22.2.5.1.2 - time_get virtual functions
27// ISO C++ 14882: 22.2.5.3.2 - time_put virtual functions
28//
29
30// Written by Benjamin Kosnik <bkoz@redhat.com>
31
32#include <locale>
4ba851b5 33#include <cstdlib>
538075fe 34#include <cstring>
1ab65677 35
12ffa228
BK
36namespace std _GLIBCXX_VISIBILITY(default)
37{
38_GLIBCXX_BEGIN_NAMESPACE_VERSION
3cbc7af0 39
da5c0f6e
BK
40 template<>
41 void
42 __timepunct<char>::
32ade559
BK
43 _M_put(char* __s, size_t __maxlen, const char* __format,
44 const tm* __tm) const throw()
da5c0f6e 45 {
445877a9 46 char* __old = setlocale(LC_ALL, 0);
538075fe
PC
47 const size_t __llen = strlen(__old) + 1;
48 char* __sav = new char[__llen];
49 memcpy(__sav, __old, __llen);
6d030676 50 setlocale(LC_ALL, _M_name_timepunct);
cb793089 51 const size_t __len = strftime(__s, __maxlen, __format, __tm);
538075fe
PC
52 setlocale(LC_ALL, __sav);
53 delete [] __sav;
cb793089
PC
54 // Make sure __s is null terminated.
55 if (__len == 0)
56 __s[0] = '\0';
da5c0f6e
BK
57 }
58
32ade559 59 template<>
1ab65677
BK
60 void
61 __timepunct<char>::_M_initialize_timepunct(__c_locale)
32ade559 62 {
fea4065d
BK
63 // "C" locale.
64 if (!_M_data)
65 _M_data = new __timepunct_cache<char>;
66
67 _M_data->_M_date_format = "%m/%d/%y";
68 _M_data->_M_date_era_format = "%m/%d/%y";
69 _M_data->_M_time_format = "%H:%M:%S";
70 _M_data->_M_time_era_format = "%H:%M:%S";
71 _M_data->_M_date_time_format = "";
72 _M_data->_M_date_time_era_format = "";
73 _M_data->_M_am = "AM";
74 _M_data->_M_pm = "PM";
75 _M_data->_M_am_pm_format = "";
32ade559 76
1ab65677 77 // Day names, starting with "C"'s Sunday.
fea4065d
BK
78 _M_data->_M_day1 = "Sunday";
79 _M_data->_M_day2 = "Monday";
80 _M_data->_M_day3 = "Tuesday";
81 _M_data->_M_day4 = "Wednesday";
82 _M_data->_M_day5 = "Thursday";
83 _M_data->_M_day6 = "Friday";
84 _M_data->_M_day7 = "Saturday";
1ab65677
BK
85
86 // Abbreviated day names, starting with "C"'s Sun.
fea4065d
BK
87 _M_data->_M_aday1 = "Sun";
88 _M_data->_M_aday2 = "Mon";
89 _M_data->_M_aday3 = "Tue";
90 _M_data->_M_aday4 = "Wed";
91 _M_data->_M_aday5 = "Thu";
92 _M_data->_M_aday6 = "Fri";
93 _M_data->_M_aday7 = "Sat";
1ab65677
BK
94
95 // Month names, starting with "C"'s January.
fea4065d
BK
96 _M_data->_M_month01 = "January";
97 _M_data->_M_month02 = "February";
98 _M_data->_M_month03 = "March";
99 _M_data->_M_month04 = "April";
100 _M_data->_M_month05 = "May";
101 _M_data->_M_month06 = "June";
102 _M_data->_M_month07 = "July";
103 _M_data->_M_month08 = "August";
104 _M_data->_M_month09 = "September";
105 _M_data->_M_month10 = "October";
106 _M_data->_M_month11 = "November";
107 _M_data->_M_month12 = "December";
1ab65677
BK
108
109 // Abbreviated month names, starting with "C"'s Jan.
fea4065d
BK
110 _M_data->_M_amonth01 = "Jan";
111 _M_data->_M_amonth02 = "Feb";
112 _M_data->_M_amonth03 = "Mar";
113 _M_data->_M_amonth04 = "Apr";
114 _M_data->_M_amonth05 = "May";
115 _M_data->_M_amonth06 = "Jun";
ba98a8d8 116 _M_data->_M_amonth07 = "Jul";
fea4065d
BK
117 _M_data->_M_amonth08 = "Aug";
118 _M_data->_M_amonth09 = "Sep";
119 _M_data->_M_amonth10 = "Oct";
120 _M_data->_M_amonth11 = "Nov";
121 _M_data->_M_amonth12 = "Dec";
1ab65677
BK
122 }
123
3d7c150e 124#ifdef _GLIBCXX_USE_WCHAR_T
da5c0f6e
BK
125 template<>
126 void
127 __timepunct<wchar_t>::
32ade559
BK
128 _M_put(wchar_t* __s, size_t __maxlen, const wchar_t* __format,
129 const tm* __tm) const throw()
da5c0f6e 130 {
445877a9 131 char* __old = setlocale(LC_ALL, 0);
538075fe
PC
132 const size_t __llen = strlen(__old) + 1;
133 char* __sav = new char[__llen];
134 memcpy(__sav, __old, __llen);
6d030676 135 setlocale(LC_ALL, _M_name_timepunct);
cb793089 136 const size_t __len = wcsftime(__s, __maxlen, __format, __tm);
538075fe
PC
137 setlocale(LC_ALL, __sav);
138 delete [] __sav;
cb793089
PC
139 // Make sure __s is null terminated.
140 if (__len == 0)
32ade559 141 __s[0] = L'\0';
da5c0f6e
BK
142 }
143
32ade559 144 template<>
1ab65677
BK
145 void
146 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale)
da5c0f6e 147 {
fea4065d
BK
148 // "C" locale.
149 if (!_M_data)
150 _M_data = new __timepunct_cache<wchar_t>;
151
152 _M_data->_M_date_format = L"%m/%d/%y";
153 _M_data->_M_date_era_format = L"%m/%d/%y";
154 _M_data->_M_time_format = L"%H:%M:%S";
155 _M_data->_M_time_era_format = L"%H:%M:%S";
156 _M_data->_M_date_time_format = L"";
157 _M_data->_M_date_time_era_format = L"";
158 _M_data->_M_am = L"AM";
159 _M_data->_M_pm = L"PM";
160 _M_data->_M_am_pm_format = L"";
da5c0f6e
BK
161
162 // Day names, starting with "C"'s Sunday.
fea4065d
BK
163 _M_data->_M_day1 = L"Sunday";
164 _M_data->_M_day2 = L"Monday";
165 _M_data->_M_day3 = L"Tuesday";
166 _M_data->_M_day4 = L"Wednesday";
167 _M_data->_M_day5 = L"Thursday";
168 _M_data->_M_day6 = L"Friday";
169 _M_data->_M_day7 = L"Saturday";
da5c0f6e
BK
170
171 // Abbreviated day names, starting with "C"'s Sun.
fea4065d
BK
172 _M_data->_M_aday1 = L"Sun";
173 _M_data->_M_aday2 = L"Mon";
174 _M_data->_M_aday3 = L"Tue";
175 _M_data->_M_aday4 = L"Wed";
176 _M_data->_M_aday5 = L"Thu";
177 _M_data->_M_aday6 = L"Fri";
178 _M_data->_M_aday7 = L"Sat";
da5c0f6e
BK
179
180 // Month names, starting with "C"'s January.
fea4065d
BK
181 _M_data->_M_month01 = L"January";
182 _M_data->_M_month02 = L"February";
183 _M_data->_M_month03 = L"March";
184 _M_data->_M_month04 = L"April";
185 _M_data->_M_month05 = L"May";
186 _M_data->_M_month06 = L"June";
187 _M_data->_M_month07 = L"July";
188 _M_data->_M_month08 = L"August";
189 _M_data->_M_month09 = L"September";
190 _M_data->_M_month10 = L"October";
191 _M_data->_M_month11 = L"November";
192 _M_data->_M_month12 = L"December";
da5c0f6e
BK
193
194 // Abbreviated month names, starting with "C"'s Jan.
fea4065d
BK
195 _M_data->_M_amonth01 = L"Jan";
196 _M_data->_M_amonth02 = L"Feb";
197 _M_data->_M_amonth03 = L"Mar";
198 _M_data->_M_amonth04 = L"Apr";
199 _M_data->_M_amonth05 = L"May";
200 _M_data->_M_amonth06 = L"Jun";
ba98a8d8 201 _M_data->_M_amonth07 = L"Jul";
fea4065d
BK
202 _M_data->_M_amonth08 = L"Aug";
203 _M_data->_M_amonth09 = L"Sep";
204 _M_data->_M_amonth10 = L"Oct";
205 _M_data->_M_amonth11 = L"Nov";
206 _M_data->_M_amonth12 = L"Dec";
da5c0f6e 207 }
1ab65677 208#endif
3cbc7af0 209
12ffa228
BK
210_GLIBCXX_END_NAMESPACE_VERSION
211} // namespace