1 // std::time_get, std::time_put implementation, generic version -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010
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 3, 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 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
27 // ISO C++ 14882: 22.2.5.1.2 - time_get virtual functions
28 // ISO C++ 14882: 22.2.5.3.2 - time_put virtual functions
31 // Written by Benjamin Kosnik <bkoz@redhat.com>
37 namespace std
_GLIBCXX_VISIBILITY(default)
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
44 _M_put(char* __s
, size_t __maxlen
, const char* __format
,
45 const tm
* __tm
) const throw()
47 char* __old
= setlocale(LC_ALL
, 0);
48 const size_t __llen
= strlen(__old
) + 1;
49 char* __sav
= new char[__llen
];
50 memcpy(__sav
, __old
, __llen
);
51 setlocale(LC_ALL
, _M_name_timepunct
);
52 const size_t __len
= strftime(__s
, __maxlen
, __format
, __tm
);
53 setlocale(LC_ALL
, __sav
);
55 // Make sure __s is null terminated.
62 __timepunct
<char>::_M_initialize_timepunct(__c_locale
)
66 _M_data
= new __timepunct_cache
<char>;
68 _M_data
->_M_date_format
= "%m/%d/%y";
69 _M_data
->_M_date_era_format
= "%m/%d/%y";
70 _M_data
->_M_time_format
= "%H:%M:%S";
71 _M_data
->_M_time_era_format
= "%H:%M:%S";
72 _M_data
->_M_date_time_format
= "";
73 _M_data
->_M_date_time_era_format
= "";
74 _M_data
->_M_am
= "AM";
75 _M_data
->_M_pm
= "PM";
76 _M_data
->_M_am_pm_format
= "";
78 // Day names, starting with "C"'s Sunday.
79 _M_data
->_M_day1
= "Sunday";
80 _M_data
->_M_day2
= "Monday";
81 _M_data
->_M_day3
= "Tuesday";
82 _M_data
->_M_day4
= "Wednesday";
83 _M_data
->_M_day5
= "Thursday";
84 _M_data
->_M_day6
= "Friday";
85 _M_data
->_M_day7
= "Saturday";
87 // Abbreviated day names, starting with "C"'s Sun.
88 _M_data
->_M_aday1
= "Sun";
89 _M_data
->_M_aday2
= "Mon";
90 _M_data
->_M_aday3
= "Tue";
91 _M_data
->_M_aday4
= "Wed";
92 _M_data
->_M_aday5
= "Thu";
93 _M_data
->_M_aday6
= "Fri";
94 _M_data
->_M_aday7
= "Sat";
96 // Month names, starting with "C"'s January.
97 _M_data
->_M_month01
= "January";
98 _M_data
->_M_month02
= "February";
99 _M_data
->_M_month03
= "March";
100 _M_data
->_M_month04
= "April";
101 _M_data
->_M_month05
= "May";
102 _M_data
->_M_month06
= "June";
103 _M_data
->_M_month07
= "July";
104 _M_data
->_M_month08
= "August";
105 _M_data
->_M_month09
= "September";
106 _M_data
->_M_month10
= "October";
107 _M_data
->_M_month11
= "November";
108 _M_data
->_M_month12
= "December";
110 // Abbreviated month names, starting with "C"'s Jan.
111 _M_data
->_M_amonth01
= "Jan";
112 _M_data
->_M_amonth02
= "Feb";
113 _M_data
->_M_amonth03
= "Mar";
114 _M_data
->_M_amonth04
= "Apr";
115 _M_data
->_M_amonth05
= "May";
116 _M_data
->_M_amonth06
= "Jun";
117 _M_data
->_M_amonth07
= "Jul";
118 _M_data
->_M_amonth08
= "Aug";
119 _M_data
->_M_amonth09
= "Sep";
120 _M_data
->_M_amonth10
= "Oct";
121 _M_data
->_M_amonth11
= "Nov";
122 _M_data
->_M_amonth12
= "Dec";
125 #ifdef _GLIBCXX_USE_WCHAR_T
128 __timepunct
<wchar_t>::
129 _M_put(wchar_t* __s
, size_t __maxlen
, const wchar_t* __format
,
130 const tm
* __tm
) const throw()
132 char* __old
= setlocale(LC_ALL
, 0);
133 const size_t __llen
= strlen(__old
) + 1;
134 char* __sav
= new char[__llen
];
135 memcpy(__sav
, __old
, __llen
);
136 setlocale(LC_ALL
, _M_name_timepunct
);
137 const size_t __len
= wcsftime(__s
, __maxlen
, __format
, __tm
);
138 setlocale(LC_ALL
, __sav
);
140 // Make sure __s is null terminated.
147 __timepunct
<wchar_t>::_M_initialize_timepunct(__c_locale
)
151 _M_data
= new __timepunct_cache
<wchar_t>;
153 _M_data
->_M_date_format
= L
"%m/%d/%y";
154 _M_data
->_M_date_era_format
= L
"%m/%d/%y";
155 _M_data
->_M_time_format
= L
"%H:%M:%S";
156 _M_data
->_M_time_era_format
= L
"%H:%M:%S";
157 _M_data
->_M_date_time_format
= L
"";
158 _M_data
->_M_date_time_era_format
= L
"";
159 _M_data
->_M_am
= L
"AM";
160 _M_data
->_M_pm
= L
"PM";
161 _M_data
->_M_am_pm_format
= L
"";
163 // Day names, starting with "C"'s Sunday.
164 _M_data
->_M_day1
= L
"Sunday";
165 _M_data
->_M_day2
= L
"Monday";
166 _M_data
->_M_day3
= L
"Tuesday";
167 _M_data
->_M_day4
= L
"Wednesday";
168 _M_data
->_M_day5
= L
"Thursday";
169 _M_data
->_M_day6
= L
"Friday";
170 _M_data
->_M_day7
= L
"Saturday";
172 // Abbreviated day names, starting with "C"'s Sun.
173 _M_data
->_M_aday1
= L
"Sun";
174 _M_data
->_M_aday2
= L
"Mon";
175 _M_data
->_M_aday3
= L
"Tue";
176 _M_data
->_M_aday4
= L
"Wed";
177 _M_data
->_M_aday5
= L
"Thu";
178 _M_data
->_M_aday6
= L
"Fri";
179 _M_data
->_M_aday7
= L
"Sat";
181 // Month names, starting with "C"'s January.
182 _M_data
->_M_month01
= L
"January";
183 _M_data
->_M_month02
= L
"February";
184 _M_data
->_M_month03
= L
"March";
185 _M_data
->_M_month04
= L
"April";
186 _M_data
->_M_month05
= L
"May";
187 _M_data
->_M_month06
= L
"June";
188 _M_data
->_M_month07
= L
"July";
189 _M_data
->_M_month08
= L
"August";
190 _M_data
->_M_month09
= L
"September";
191 _M_data
->_M_month10
= L
"October";
192 _M_data
->_M_month11
= L
"November";
193 _M_data
->_M_month12
= L
"December";
195 // Abbreviated month names, starting with "C"'s Jan.
196 _M_data
->_M_amonth01
= L
"Jan";
197 _M_data
->_M_amonth02
= L
"Feb";
198 _M_data
->_M_amonth03
= L
"Mar";
199 _M_data
->_M_amonth04
= L
"Apr";
200 _M_data
->_M_amonth05
= L
"May";
201 _M_data
->_M_amonth06
= L
"Jun";
202 _M_data
->_M_amonth07
= L
"Jul";
203 _M_data
->_M_amonth08
= L
"Aug";
204 _M_data
->_M_amonth09
= L
"Sep";
205 _M_data
->_M_amonth10
= L
"Oct";
206 _M_data
->_M_amonth11
= L
"Nov";
207 _M_data
->_M_amonth12
= L
"Dec";
211 _GLIBCXX_END_NAMESPACE_VERSION