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