]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/config/locale/generic/time_members.cc
[multiple changes]
[thirdparty/gcc.git] / libstdc++-v3 / config / locale / generic / time_members.cc
1 // std::time_get, std::time_put implementation, GNU version -*- C++ -*-
2
3 // Copyright (C) 2001, 2002 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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 __timepunct<char>::~__timepunct()
43 {
44 if (_M_c_locale_timepunct != _S_c_locale)
45 _S_destroy_c_locale(_M_c_locale_timepunct);
46 }
47
48 template<>
49 void
50 __timepunct<char>::
51 _M_put(char* __s, size_t __maxlen, const char* __format,
52 const tm* __tm) const
53 {
54 char* __old = strdup(setlocale(LC_ALL, NULL));
55 setlocale(LC_ALL, _M_name_timepunct);
56 strftime(__s, __maxlen, __format, __tm);
57 setlocale(LC_ALL, __old);
58 free(__old);
59 }
60
61 template<>
62 void
63 __timepunct<char>::_M_initialize_timepunct(__c_locale)
64 {
65 // "C" locale
66 _M_date_format = "%m/%d/%Y";
67 _M_date_era_format = "%m/%d/%Y";
68 _M_time_format = "%H:%M:%S";
69 _M_time_era_format = "%H:%M:%S";
70 _M_date_time_format = "";
71 _M_date_time_era_format = "";
72 _M_am = "AM";
73 _M_pm = "PM";
74 _M_am_pm_format = "";
75
76 // Day names, starting with "C"'s Sunday.
77 _M_day1 = "Sunday";
78 _M_day2 = "Monday";
79 _M_day3 = "Tuesday";
80 _M_day4 = "Wednesday";
81 _M_day5 = "Thursday";
82 _M_day6 = "Friday";
83 _M_day7 = "Saturday";
84
85 // Abbreviated day names, starting with "C"'s Sun.
86 _M_day_a1 = "Sun";
87 _M_day_a2 = "Mon";
88 _M_day_a3 = "Tue";
89 _M_day_a4 = "Wed";
90 _M_day_a5 = "Thu";
91 _M_day_a6 = "Fri";
92 _M_day_a7 = "Sat";
93
94 // Month names, starting with "C"'s January.
95 _M_month01 = "January";
96 _M_month02 = "February";
97 _M_month03 = "March";
98 _M_month04 = "April";
99 _M_month05 = "May";
100 _M_month06 = "June";
101 _M_month07 = "July";
102 _M_month08 = "August";
103 _M_month09 = "September";
104 _M_month10 = "October";
105 _M_month11 = "November";
106 _M_month12 = "December";
107
108 // Abbreviated month names, starting with "C"'s Jan.
109 _M_month_a01 = "Jan";
110 _M_month_a02 = "Feb";
111 _M_month_a03 = "Mar";
112 _M_month_a04 = "Apr";
113 _M_month_a05 = "May";
114 _M_month_a06 = "Jun";
115 _M_month_a07 = "July";
116 _M_month_a08 = "Aug";
117 _M_month_a09 = "Sep";
118 _M_month_a10 = "Oct";
119 _M_month_a11 = "Nov";
120 _M_month_a12 = "Dec";
121 }
122
123 #ifdef _GLIBCPP_USE_WCHAR_T
124 template<>
125 __timepunct<wchar_t>::~__timepunct()
126 {
127 if (_M_c_locale_timepunct != _S_c_locale)
128 _S_destroy_c_locale(_M_c_locale_timepunct);
129 }
130
131 template<>
132 void
133 __timepunct<wchar_t>::
134 _M_put(wchar_t* __s, size_t __maxlen, const wchar_t* __format,
135 const tm* __tm) const
136 {
137 char* __old = strdup(setlocale(LC_ALL, NULL));
138 setlocale(LC_ALL, _M_name_timepunct);
139 wcsftime(__s, __maxlen, __format, __tm);
140 setlocale(LC_ALL, __old);
141 free(__old);
142 }
143
144 template<>
145 void
146 __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale)
147 {
148 // "C" locale
149 _M_date_format = L"%m/%d/%y";
150 _M_date_era_format = L"%m/%d/%y";
151 _M_time_format = L"%H:%M:%S";
152 _M_time_era_format = L"%H:%M:%S";
153 _M_date_time_format = L"";
154 _M_date_time_era_format = L"";
155 _M_am = L"AM";
156 _M_pm = L"PM";
157 _M_am_pm_format = L"";
158
159 // Day names, starting with "C"'s Sunday.
160 _M_day1 = L"Sunday";
161 _M_day2 = L"Monday";
162 _M_day3 = L"Tuesday";
163 _M_day4 = L"Wednesday";
164 _M_day5 = L"Thursday";
165 _M_day6 = L"Friday";
166 _M_day7 = L"Saturday";
167
168 // Abbreviated day names, starting with "C"'s Sun.
169 _M_day_a1 = L"Sun";
170 _M_day_a2 = L"Mon";
171 _M_day_a3 = L"Tue";
172 _M_day_a4 = L"Wed";
173 _M_day_a5 = L"Thu";
174 _M_day_a6 = L"Fri";
175 _M_day_a7 = L"Sat";
176
177 // Month names, starting with "C"'s January.
178 _M_month01 = L"January";
179 _M_month02 = L"February";
180 _M_month03 = L"March";
181 _M_month04 = L"April";
182 _M_month05 = L"May";
183 _M_month06 = L"June";
184 _M_month07 = L"July";
185 _M_month08 = L"August";
186 _M_month09 = L"September";
187 _M_month10 = L"October";
188 _M_month11 = L"November";
189 _M_month12 = L"December";
190
191 // Abbreviated month names, starting with "C"'s Jan.
192 _M_month_a01 = L"Jan";
193 _M_month_a02 = L"Feb";
194 _M_month_a03 = L"Mar";
195 _M_month_a04 = L"Apr";
196 _M_month_a05 = L"May";
197 _M_month_a06 = L"Jun";
198 _M_month_a07 = L"July";
199 _M_month_a08 = L"Aug";
200 _M_month_a09 = L"Sep";
201 _M_month_a10 = L"Oct";
202 _M_month_a11 = L"Nov";
203 _M_month_a12 = L"Dec";
204 }
205 #endif
206 }