uifw/AvKon/src/AknDateFormatUtils.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2003 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:  Implementation of visual - Symbian OS date formats for 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AknDateFormatUtils.h>
       
    20 
       
    21 #include <biditext.h>
       
    22 #include <e32std.h>
       
    23 #include <AknUtils.h>
       
    24 
       
    25 /**
       
    26 * Current implementation of this should work for any RTL language if it sets the 
       
    27 * digit type to digit types checked for below
       
    28 *
       
    29 * It is meant as a patch for S60 2.0, not as a complete solution to the problem of date
       
    30 * presentation.
       
    31 */
       
    32 TBool AknDateFormatUtils::DateFieldReOrderingNeeded(TLanguage* aForceLanguage )
       
    33     {
       
    34     TBool reorderingNeeded(EFalse);
       
    35     TLocale locale;
       
    36     TLanguage language = (aForceLanguage != NULL) ? *aForceLanguage : AknLangUtils::UserLanguage();
       
    37 
       
    38     // Reordering needed in case of RTL language, we have arabic digits and if the separator is not 
       
    39     // numeric separator.
       
    40      if ( TBidiText::ScriptDirectionality( language ) == TBidiText::ERightToLeft )
       
    41         {
       
    42         TInt digitType = locale.DigitType();
       
    43         if ( digitType == EDigitTypeArabicIndic ||
       
    44              digitType == EDigitTypeEasternArabicIndic )
       
    45             {
       
    46             TChar sep( locale.DateSeparator(1) );
       
    47             if ( sep.GetBdCategory() != TChar::ECommonNumberSeparator )
       
    48                 {
       
    49                 reorderingNeeded = ETrue;
       
    50                 }
       
    51             }
       
    52         }
       
    53         
       
    54     return reorderingNeeded;
       
    55     }
       
    56 
       
    57 TAknVisualDateFormat AknDateFormatUtils::MapSymbianDateFormatToWesternVisualDateFormat(
       
    58     TDateFormat aFormat )
       
    59     {
       
    60     TAknVisualDateFormat visualFormat(EVisualDayMonthYear);
       
    61     switch ( aFormat )
       
    62         {
       
    63         case EDateEuropean:
       
    64             visualFormat = EVisualDayMonthYear;
       
    65             break;
       
    66 
       
    67         case EDateAmerican:
       
    68             visualFormat = EVisualMonthDayYear;
       
    69             break;
       
    70 
       
    71         case EDateJapanese:
       
    72             visualFormat = EVisualYearMonthDay;
       
    73             break;
       
    74         }
       
    75     return visualFormat;
       
    76     }
       
    77 
       
    78 TDateFormat AknDateFormatUtils::MapWesternVisualDateFormatToSymbianDateFormat(
       
    79     TAknVisualDateFormat aFormat )
       
    80     {
       
    81     TDateFormat osFormat(EDateEuropean);
       
    82     switch( aFormat )
       
    83         {
       
    84         case EVisualDayMonthYear:
       
    85         osFormat = EDateEuropean;
       
    86             break;
       
    87         case EVisualMonthDayYear:
       
    88             osFormat = EDateAmerican;
       
    89             break;
       
    90         case EVisualYearMonthDay:
       
    91             osFormat = EDateJapanese;
       
    92             break;
       
    93         }
       
    94     return osFormat;
       
    95     }
       
    96 
       
    97 EXPORT_C TAknVisualDateFormat AknDateFormatUtils::MapSymbianDateFormatToVisualDateFormat(
       
    98     TDateFormat aFormat, TLanguage* aForceLanguage )
       
    99     {
       
   100     // Get the western mapping first
       
   101     TAknVisualDateFormat visualFormat = 
       
   102         MapSymbianDateFormatToWesternVisualDateFormat( aFormat );
       
   103 
       
   104     if ( DateFieldReOrderingNeeded( aForceLanguage ) )
       
   105         {
       
   106         if ( visualFormat == EVisualDayMonthYear ) 
       
   107             visualFormat = EVisualYearMonthDay;
       
   108         else if ( visualFormat == EVisualYearMonthDay )
       
   109             visualFormat =  EVisualDayMonthYear;
       
   110         }
       
   111 
       
   112     return visualFormat;
       
   113     }
       
   114 
       
   115 EXPORT_C TDateFormat AknDateFormatUtils::MapVisualDateFormatToSymbianDateFormat(
       
   116     TAknVisualDateFormat aFormat, TLanguage* aForceLanguage ) 
       
   117     {
       
   118     // Get the western mapping first
       
   119     TDateFormat osFormat = 
       
   120         MapWesternVisualDateFormatToSymbianDateFormat( aFormat );
       
   121 
       
   122     if ( DateFieldReOrderingNeeded( aForceLanguage ) )
       
   123         {
       
   124         if ( osFormat == EDateEuropean ) 
       
   125             osFormat = EDateJapanese;
       
   126         else if ( osFormat == EDateJapanese )
       
   127             osFormat =  EDateEuropean;
       
   128         }
       
   129     return osFormat;
       
   130     }