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