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