os/ossrv/genericopenlibs/openenvcore/libc/src/timelocal.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:  Contains the source for LC_TIME category related functions
    15  *     
    16  *
    17 */
    18 
    19  
    20 #include <stddef.h>
    21 #include "localeinfo.h"
    22 #include "timelocal.h"
    23 
    24 #if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__)))
    25 #include "libc_wsd_defs.h"
    26 #endif
    27 
    28 extern int __nlocale_changed;
    29 #ifdef EMULATOR
    30 int *GET_WSD_VAR_NAME(__nlocale_changed, g)();
    31 #define __nlocale_changed (*GET_WSD_VAR_NAME(__nlocale_changed, g)())
    32 #endif //EMULATOR
    33 
    34 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
    35 extern unsigned char __clocale_set;
    36 #ifdef EMULATOR
    37 unsigned char *GET_WSD_VAR_NAME(__clocale_set, g)();
    38 #define __clocale_set (*GET_WSD_VAR_NAME(__clocale_set, g)())
    39 #endif //EMULATOR
    40 #endif
    41 #ifndef EMULATOR
    42 int _time_using_locale = 0;
    43 #else //EMULATOR
    44 
    45 GET_GLOBAL_VAR_FROM_TLS(_time_using_locale, int)
    46 #define _time_using_locale (*GET_WSD_VAR_NAME(_time_using_locale, g)())
    47 #endif //EMULATOR
    48 
    49 static const struct lc_time_T	_C_time_locale = {
    50 	{
    51 		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
    52 		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
    53 	}, {
    54 		"January", "February", "March", "April", "May", "June",
    55 		"July", "August", "September", "October", "November", "December"
    56 	}, {
    57 		"Sun", "Mon", "Tue", "Wed",
    58 		"Thu", "Fri", "Sat"
    59 	}, {
    60 		"Sunday", "Monday", "Tuesday", "Wednesday",
    61 		"Thursday", "Friday", "Saturday"
    62 	},
    63 
    64 	/* X_fmt */
    65 	"%H:%M:%S",
    66 
    67 	/*
    68 	 * x_fmt
    69 	 * Since the C language standard calls for
    70 	 * "date, using locale's date format," anything goes.
    71 	 * Using just numbers (as here) makes Quakers happier;
    72 	 * it's also compatible with SVR4.
    73 	 */
    74 	"%m/%d/%y",
    75 
    76 	/*
    77 	 * c_fmt
    78 	 */
    79 	"%a %b %e %H:%M:%S %Y",
    80 
    81 	/* am */
    82 	"AM",
    83 
    84 	/* pm */
    85 	"PM",
    86 
    87 	/* date_fmt */
    88 	"%a %b %e %H:%M:%S %Z %Y",
    89 	
    90 	/* alt_month
    91 	 * Standalone months forms for %OB
    92 	 */
    93 	{
    94 		"January", "February", "March", "April", "May", "June",
    95 		"July", "August", "September", "October", "November", "December"
    96 	},
    97 
    98 	/* md_order
    99 	 * Month / day order in dates
   100 	 */
   101 	"md",
   102 
   103 	/* ampm_fmt
   104 	 * To determine 12-hour clock format time (empty, if N/A)
   105 	 */
   106 	"%I:%M:%S %p"
   107 };
   108 
   109 struct lc_time_T *
   110 __get_current_time_locale(void)
   111 {
   112 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
   113     TInt ret;
   114 #endif
   115 	//retrieve time(LC_TIME category) related information
   116 	if(_time_using_locale)
   117 	{
   118 		return (CLocale::GetCurrentTimeLocale());
   119 	}
   120 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
   121     else if(__clocale_set)	
   122 #endif
   123 	//Retrieve POSIX locale time(LC_TIME) information
   124 	return (struct lc_time_T *)&_C_time_locale;
   125 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
   126 	else
   127 	{
   128 		CLocale *l=CLocale::GetInstance();
   129 		ret=l->SyncLocale(ELocaleLanguageSettings);
   130     	if(ret==-1)
   131     	return NULL;
   132     	TRAPD(result, l->TimeLoadLocaleL(NULL));
   133     	if((result != KErrNone))
   134 		return NULL;
   135 		return (CLocale::GetCurrentTimeLocale());
   136 	}
   137 #endif
   138 }
   139 
   140 int
   141 __time_load_locale(const char* localeName)
   142 {
   143 
   144 	CLocale* locale = CLocale::GetInstance();	
   145 	//Set time(LC_TIME category) related information
   146 	TInt ret=KErrNone;
   147 	TRAPD(result,ret = locale->TimeLoadLocaleL(localeName));
   148 	if((result != KErrNone) || (ret == -1))
   149 	{
   150 		return -1;
   151 	}
   152 	_time_using_locale = 1;
   153 	return 0;
   154 
   155 }