1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libc/src/timelocal.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,155 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description: Contains the source for LC_TIME category related functions
1.18 + *
1.19 + *
1.20 +*/
1.21 +
1.22 +
1.23 +#include <stddef.h>
1.24 +#include "localeinfo.h"
1.25 +#include "timelocal.h"
1.26 +
1.27 +#if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__)))
1.28 +#include "libc_wsd_defs.h"
1.29 +#endif
1.30 +
1.31 +extern int __nlocale_changed;
1.32 +#ifdef EMULATOR
1.33 +int *GET_WSD_VAR_NAME(__nlocale_changed, g)();
1.34 +#define __nlocale_changed (*GET_WSD_VAR_NAME(__nlocale_changed, g)())
1.35 +#endif //EMULATOR
1.36 +
1.37 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.38 +extern unsigned char __clocale_set;
1.39 +#ifdef EMULATOR
1.40 +unsigned char *GET_WSD_VAR_NAME(__clocale_set, g)();
1.41 +#define __clocale_set (*GET_WSD_VAR_NAME(__clocale_set, g)())
1.42 +#endif //EMULATOR
1.43 +#endif
1.44 +#ifndef EMULATOR
1.45 +int _time_using_locale = 0;
1.46 +#else //EMULATOR
1.47 +
1.48 +GET_GLOBAL_VAR_FROM_TLS(_time_using_locale, int)
1.49 +#define _time_using_locale (*GET_WSD_VAR_NAME(_time_using_locale, g)())
1.50 +#endif //EMULATOR
1.51 +
1.52 +static const struct lc_time_T _C_time_locale = {
1.53 + {
1.54 + "Jan", "Feb", "Mar", "Apr", "May", "Jun",
1.55 + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
1.56 + }, {
1.57 + "January", "February", "March", "April", "May", "June",
1.58 + "July", "August", "September", "October", "November", "December"
1.59 + }, {
1.60 + "Sun", "Mon", "Tue", "Wed",
1.61 + "Thu", "Fri", "Sat"
1.62 + }, {
1.63 + "Sunday", "Monday", "Tuesday", "Wednesday",
1.64 + "Thursday", "Friday", "Saturday"
1.65 + },
1.66 +
1.67 + /* X_fmt */
1.68 + "%H:%M:%S",
1.69 +
1.70 + /*
1.71 + * x_fmt
1.72 + * Since the C language standard calls for
1.73 + * "date, using locale's date format," anything goes.
1.74 + * Using just numbers (as here) makes Quakers happier;
1.75 + * it's also compatible with SVR4.
1.76 + */
1.77 + "%m/%d/%y",
1.78 +
1.79 + /*
1.80 + * c_fmt
1.81 + */
1.82 + "%a %b %e %H:%M:%S %Y",
1.83 +
1.84 + /* am */
1.85 + "AM",
1.86 +
1.87 + /* pm */
1.88 + "PM",
1.89 +
1.90 + /* date_fmt */
1.91 + "%a %b %e %H:%M:%S %Z %Y",
1.92 +
1.93 + /* alt_month
1.94 + * Standalone months forms for %OB
1.95 + */
1.96 + {
1.97 + "January", "February", "March", "April", "May", "June",
1.98 + "July", "August", "September", "October", "November", "December"
1.99 + },
1.100 +
1.101 + /* md_order
1.102 + * Month / day order in dates
1.103 + */
1.104 + "md",
1.105 +
1.106 + /* ampm_fmt
1.107 + * To determine 12-hour clock format time (empty, if N/A)
1.108 + */
1.109 + "%I:%M:%S %p"
1.110 +};
1.111 +
1.112 +struct lc_time_T *
1.113 +__get_current_time_locale(void)
1.114 +{
1.115 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.116 + TInt ret;
1.117 +#endif
1.118 + //retrieve time(LC_TIME category) related information
1.119 + if(_time_using_locale)
1.120 + {
1.121 + return (CLocale::GetCurrentTimeLocale());
1.122 + }
1.123 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.124 + else if(__clocale_set)
1.125 +#endif
1.126 + //Retrieve POSIX locale time(LC_TIME) information
1.127 + return (struct lc_time_T *)&_C_time_locale;
1.128 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
1.129 + else
1.130 + {
1.131 + CLocale *l=CLocale::GetInstance();
1.132 + ret=l->SyncLocale(ELocaleLanguageSettings);
1.133 + if(ret==-1)
1.134 + return NULL;
1.135 + TRAPD(result, l->TimeLoadLocaleL(NULL));
1.136 + if((result != KErrNone))
1.137 + return NULL;
1.138 + return (CLocale::GetCurrentTimeLocale());
1.139 + }
1.140 +#endif
1.141 +}
1.142 +
1.143 +int
1.144 +__time_load_locale(const char* localeName)
1.145 +{
1.146 +
1.147 + CLocale* locale = CLocale::GetInstance();
1.148 + //Set time(LC_TIME category) related information
1.149 + TInt ret=KErrNone;
1.150 + TRAPD(result,ret = locale->TimeLoadLocaleL(localeName));
1.151 + if((result != KErrNone) || (ret == -1))
1.152 + {
1.153 + return -1;
1.154 + }
1.155 + _time_using_locale = 1;
1.156 + return 0;
1.157 +
1.158 +}