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