DateTime.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:71k
源码类别:

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  * DateTime.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  * This file implements date/time related utilities for other applications
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  * removed!
  104.  * removed!
  105.  * removed!
  106.  *
  107.  * removed!
  108.  * removed!
  109.  * removed!
  110.  *
  111.  * removed!
  112.  * removed!
  113.  * removed!
  114.  *
  115.  * removed!
  116.  * removed!
  117.  * removed!
  118.  *
  119.  * removed!
  120.  * removed!
  121.  * removed!
  122.  *
  123.  * removed!
  124.  * removed!
  125.  * removed!
  126.  *
  127.  * removed!
  128.  * removed!
  129.  * removed!
  130.  *
  131.  * removed!
  132.  * removed!
  133.  * removed!
  134.  *
  135.  * removed!
  136.  * removed!
  137.  * removed!
  138.  *
  139.  * removed!
  140.  * removed!
  141.  * removed!
  142.  *
  143.  * removed!
  144.  * removed!
  145.  * removed!
  146.  *
  147.  *------------------------------------------------------------------------------
  148.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  149.  *============================================================================
  150.  ****************************************************************************/
  151. /*****************************************************************************
  152. *  Copyright Statement:
  153. *  --------------------
  154. *  This software is protected by Copyright and the information contained
  155. *  herein is confidential. The software may not be copied and the information
  156. *  contained herein may not be used or disclosed except with the written
  157. *  permission of MediaTek Inc. (C) 2004
  158. *
  159. *****************************************************************************/
  160. /*****************************************************************************
  161.  *
  162.  * Filename:
  163.  * ---------
  164.  * DateTime.c
  165.  *
  166.  * Project:
  167.  * --------
  168.  *   MAUI
  169.  *
  170.  * Description:
  171.  * ------------
  172.  *   This file implements date/time related utilities for other applications
  173.  *
  174.  * Author:
  175.  * -------
  176.  * -------
  177.  *
  178.  *============================================================================
  179.  *             HISTORY
  180.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  181.  *------------------------------------------------------------------------------
  182.  * removed!
  183.  * removed!
  184.  * removed!
  185.  *
  186.  * removed!
  187.  * removed!
  188.  * removed!
  189.  *
  190.  * removed!
  191.  * removed!
  192.  * removed!
  193.  *
  194.  * removed!
  195.  * removed!
  196.  * removed!
  197.  *
  198.  * removed!
  199.  * removed!
  200.  * removed!
  201.  *
  202.  * removed!
  203.  * removed!
  204.  * removed!
  205.  *
  206.  * removed!
  207.  * removed!
  208.  * removed!
  209.  *
  210.  * removed!
  211.  * removed!
  212.  * removed!
  213.  *
  214.  * removed!
  215.  * removed!
  216.  * removed!
  217.  *
  218.  * removed!
  219.  * removed!
  220.  * removed!
  221.  *
  222.  * removed!
  223.  * removed!
  224.  * removed!
  225.  *
  226.  * removed!
  227.  * removed!
  228.  * removed!
  229.  *
  230.  * removed!
  231.  * removed!
  232.  * removed!
  233.  *
  234.  * removed!
  235.  * removed!
  236.  * removed!
  237.  *
  238.  * removed!
  239.  * removed!
  240.  * removed!
  241.  *
  242.  * removed!
  243.  * removed!
  244.  * removed!
  245.  *
  246.  * removed!
  247.  * removed!
  248.  * removed!
  249.  *
  250.  * removed!
  251.  * removed!
  252.  * removed!
  253.  *
  254.  * removed!
  255.  * removed!
  256.  * removed!
  257.  *
  258.  * removed!
  259.  * removed!
  260.  * removed!
  261.  *
  262.  * removed!
  263.  * removed!
  264.  * removed!
  265.  *
  266.  * removed!
  267.  * removed!
  268.  * removed!
  269.  *
  270.  * removed!
  271.  * removed!
  272.  * removed!
  273.  * removed!
  274.  * removed!
  275.  * removed!
  276.  * removed!
  277.  * removed!
  278.  * removed!
  279.  * removed!
  280.  * removed!
  281.  * removed!
  282.  * removed!
  283.  * removed!
  284.  * removed!
  285.  * removed!
  286.  * removed!
  287.  * removed!
  288.  * removed!
  289.  * removed!
  290.  *
  291.  *------------------------------------------------------------------------------
  292.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  293.  *============================================================================
  294.  ****************************************************************************/
  295. /**
  296.  * Copyright Notice
  297.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  298.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  299.  *  (It is illegal to remove this copyright notice from this software or any
  300.  *  portion of it)
  301.  */
  302. /**************************************************************
  303.    FILENAME : DateTime.c
  304.    PURPOSE     : Utility functions to enable date and time display on idle screen
  305.    REMARKS     : nil
  306.    AUTHOR      : Neeraj Sharma, Vijay Vaidya
  307.    DATE     : Aug' 28, 2002
  308. **************************************************************/
  309. #ifndef _MMI_DATETIME_C
  310. #define _MMI_DATETIME_C
  311. #include "MMI_features.h"
  312. /*  Include: MMI header file */
  313. #include "Stdafx.h"
  314. #include "PixtelDataTypes.h"
  315. #include "DebugInitDef.h"
  316. #include "DateTimeType.h"
  317. #include "EventsGprot.h"
  318. #include "DateTimeGprot.h"
  319. #include "L4Dr.h"
  320. #include <time.h>
  321. #include "TimerEvents.h"
  322. #ifndef MMI_ON_WIN32
  323. #include "rtc_sw.h"
  324. #endif 
  325. #include "NVRAMType.h"
  326. #include "NVRAMEnum.h"
  327. #include "NVRAMProt.h"
  328. #include "SimDetectionGexdcl.h"
  329. #include "SimDetectionGprot.h"
  330. #include "AlarmFrameworkProt.h"
  331. #include "SettingStructs.h"
  332. #include "ProtocolEvents.h"
  333. #ifdef __MMI_LCD_PARTIAL_ON__
  334. #include "IdleAppProt.h"
  335. #endif 
  336. /*  Include: PS header file */
  337. /* 
  338.  * Define
  339.  */
  340. #define  DT_UTC_BASE_YEAR  1970
  341. #define  DT_MONTH_PER_YEAR    12
  342. #define  DT_DAY_PER_YEAR         365
  343. #define  DT_SEC_PER_DAY    86400
  344. #define  DT_SEC_PER_HOUR      3600
  345. #define  DT_SEC_PER_MIN    60
  346. #define MMI_DT_YEAR_BOUNDARY     30
  347. /* 
  348.  * Typedef 
  349.  */
  350. /* 
  351.  * Local Variable
  352.  */
  353. #ifdef MMI_ON_WIN32
  354. const U8 gDaysInMonth[NUM_MONTHS] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  355. #define DT_DAYS_OF_WEEK 7
  356. #endif 
  357. #ifdef MMI_ON_WIN32
  358. MYTIME MyTime = {0, 1, 1, 1, 1, 1, 0};  /* Variable used by Setting Application */
  359. S8 DateTimeStrings[2][30];              /* amitm5 to be removed as told by manju */
  360. static S8 NameOfMonth[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  361. static S8 NameOfday[7][4] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
  362. #endif /* MMI_ON_WIN32 */ 
  363. /* 
  364.  * Local Function
  365.  */
  366. static void DTResetTime(void);
  367. /* 
  368.  * Global Variable
  369.  */
  370. /* extern U8 idleScreenFirst; */
  371. U8 CMDateTimeRequest = 0;
  372. U8 CMCallCount = 0;
  373. U8 CMCallBackCount = 0;
  374. extern U8 g_dst;
  375. DateTimeFuncPtr CMDateTimeCallBack[MAX_CM_CALLS];
  376. #ifndef __MTK_TARGET__
  377. extern MYTIME MyTime;
  378. #endif 
  379. #ifndef MMI_ON_WIN32
  380. extern rtc_format_struct gclockData;
  381. #endif 
  382. #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
  383. extern BOOL gIsInSleepMode;
  384. #endif 
  385. /* 
  386.  * Global Function
  387.  */
  388. extern FLOAT GetTimeZone(U8);
  389. extern U8 PhnsetGetHomeCity(void);
  390. #ifdef MMI_ON_WIN32
  391. extern kal_uint8 g_dst;
  392. /*****************************************************************************
  393.  * FUNCTION
  394.  *  applib_dt_is_dst_enabled
  395.  * DESCRIPTION
  396.  *  Tp check if daylight saving time is enabled
  397.  * PARAMETERS
  398.  *  void
  399.  *  t  time to be computed(?)
  400.  * RETURNS
  401.  *  TURE if enabled; otherwise, false
  402.  *****************************************************************************/
  403. kal_bool applib_dt_is_dst_enabled(void)
  404. {
  405.     /*----------------------------------------------------------------*/
  406.     /* Local Variables                                                */
  407.     /*----------------------------------------------------------------*/
  408.     /*----------------------------------------------------------------*/
  409.     /* Code Body                                                      */
  410.     /*----------------------------------------------------------------*/
  411.     return (kal_bool) g_dst;
  412. }
  413. /*****************************************************************************
  414.  * FUNCTION
  415.  *  MyMonth
  416.  * DESCRIPTION
  417.  *  Fucntion to update year and month, this function is used in PC simulator only.
  418.  * PARAMETERS
  419.  *  void
  420.  * RETURNS
  421.  *  void
  422.  *****************************************************************************/
  423. void MyMonth()
  424. {
  425.     /*----------------------------------------------------------------*/
  426.     /* Local Variables                                                */
  427.     /*----------------------------------------------------------------*/
  428.     /*----------------------------------------------------------------*/
  429.     /* Code Body                                                      */
  430.     /*----------------------------------------------------------------*/
  431.     if (MyTime.nMonth == 12)
  432.     {
  433.         MyTime.nMonth = 1;
  434.         MyTime.nYear++;
  435.     }
  436.     else
  437.     {
  438.         MyTime.nMonth++;
  439.     }
  440. }
  441. /*****************************************************************************
  442.  * FUNCTION
  443.  *  DateTimerProc
  444.  * DESCRIPTION
  445.  *  Fucntion to update and display date and time. This function is used in PC simulator only.
  446.  * PARAMETERS
  447.  *  void
  448.  * RETURNS
  449.  *  void
  450.  *****************************************************************************/
  451. void DateTimerProc(void)
  452. {
  453.     /*----------------------------------------------------------------*/
  454.     /* Local Variables                                                */
  455.     /*----------------------------------------------------------------*/
  456.     //#ifdef MMI_ON_HARDWARE_P
  457.     //      L4GetClockTime();
  458.     //#else
  459.     S32 CompareDay = 28;
  460.     S16 isLeapYear = 0;
  461.     U8 nDateChanged = 0x0;
  462.     U8 update_flag = 0;
  463. /********************************************************
  464. Patch for the demo:: Min_Change_flag has been added to support low power mode.
  465. (May be we should have timer for 60 seconds).
  466. **********************************************************/
  467.     S32 Min_Change_flag = 0;
  468.     /*----------------------------------------------------------------*/
  469.     /* Code Body                                                      */
  470.     /*----------------------------------------------------------------*/
  471.     StartTimer(TIMER_REAL_TIME_CLOCK, 1000, DateTimerProc); /* 072605 Calvin added */
  472.     if (MyTime.nSec == 59)
  473.     {
  474.         MyTime.nSec = 0;
  475.         Min_Change_flag = 1;
  476.         update_flag = 1;
  477.         if (MyTime.nMin == 59)
  478.         {
  479.             MyTime.nMin = 0;
  480.             if (MyTime.nHour == 23)
  481.             {
  482.                 MyTime.nHour = 0;
  483.                 nDateChanged = 0x1;
  484.                 update_flag = 1;
  485.                 if (MyTime.DayIndex == 6)
  486.                 {
  487.                     MyTime.DayIndex = 0;
  488.                 }
  489.                 else
  490.                 {
  491.                     MyTime.DayIndex++;
  492.                 }
  493.                 switch (MyTime.nMonth)
  494.                 {
  495.                     case 1:
  496.                     case 3:
  497.                     case 5:
  498.                     case 7:
  499.                     case 8:
  500.                     case 10:
  501.                     case 12:
  502.                         if (MyTime.nDay == 31)
  503.                         {
  504.                             MyTime.nDay = 1;
  505.                             MyMonth();
  506.                         }
  507.                         else
  508.                         {
  509.                             MyTime.nDay++;
  510.                         }
  511.                         break;
  512.                     case 4:
  513.                     case 6:
  514.                     case 9:
  515.                     case 11:
  516.                         if (MyTime.nDay == 30)
  517.                         {
  518.                             MyTime.nDay = 1;
  519.                             MyMonth();
  520.                         }
  521.                         else
  522.                         {
  523.                             MyTime.nDay++;
  524.                         }
  525.                         break;
  526.                     case 2: /* Check for leap year */
  527.                         if (((MyTime.nYear % 100) == 0) && ((MyTime.nYear % 400) == 0))
  528.                         {
  529.                             isLeapYear = 1;
  530.                         }
  531.                         else if ((MyTime.nYear % 4) == 0)
  532.                         {
  533.                             isLeapYear = 1;
  534.                         }
  535.                         else    /* Not a leap year */
  536.                         {
  537.                             isLeapYear = 0;
  538.                         }
  539.                         if (isLeapYear)
  540.                         {
  541.                             CompareDay = 29;
  542.                         }
  543.                         else
  544.                         {
  545.                             CompareDay = 28;
  546.                         }
  547.                         /* (isLeapYear) ? CompareDay = 29 : CompareDay = 28; */
  548.                         if (MyTime.nDay == CompareDay)
  549.                         {
  550.                             MyTime.nDay = 1;
  551.                             MyMonth();
  552.                         }
  553.                         else
  554.                         {
  555.                             MyTime.nDay++;
  556.                         }
  557.                         break;
  558.                     default:
  559.                         break;
  560.                 }
  561.                 //Right now only for time...need to expand to accommodate year and month
  562.                 //update
  563.             }
  564.             else
  565.             {
  566.                 MyTime.nHour++;
  567.             }
  568.         }
  569.         else
  570.         {
  571.             MyTime.nMin++;
  572.         }
  573.     }
  574.     else
  575.     {
  576.         MyTime.nSec++;
  577.     }
  578.     //sprintf(DateTimeStrings[0],"%s %02d %s %d",NameOfday[MyTime.DayIndex],MyTime.nDay,NameOfMonth[MyTime.nMonth-1],MyTime.nYear);
  579.     //sprintf(DateTimeStrings[1],"%02d:%02d:%02d",MyTime.nHour,MyTime.nMin,MyTime.nSec); 
  580.     if (update_flag)
  581.     {   /* Lisen0522 */
  582.         update_mainlcd_dt_display();
  583.         update_sublcd_dt_display();
  584.     }
  585.     /*  */
  586. }
  587. /*****************************************************************************
  588.  * FUNCTION
  589.  *  InitTime
  590.  * DESCRIPTION
  591.  *  Function to initialize golbal variables and local date and time.
  592.  * PARAMETERS
  593.  *  void
  594.  * RETURNS
  595.  *  void
  596.  *****************************************************************************/
  597. void InitTime(void)
  598. {
  599. #ifdef __MTK_TARGET__
  600.     /*----------------------------------------------------------------*/
  601.     /* Local Variables                                                */
  602.     /*----------------------------------------------------------------*/
  603.     /*----------------------------------------------------------------*/
  604.     /* Code Body                                                      */
  605.     /*----------------------------------------------------------------*/
  606. #ifdef __DAILY_WALLPAPER__
  607.     memset(&gWallpaperChangeDate, 0xFF, sizeof(gWallpaperChangeDate));  /* Robin 1226 */
  608. #endif 
  609. #elif MMI_ON_WIN32
  610.     SYSTEMTIME systime;
  611.     time_t ltime;
  612.     S8 MyDay[4];
  613.     S16 i;
  614.     GetLocalTime(&systime);
  615.     time(&ltime);
  616.     strncpy(MyDay, ctime(&ltime), 3);
  617.     /* stack corruption fixed Kuldeep for Network Simulator 2.0 */
  618.     MyDay[3] = '';
  619.     /* changes done by Kuldeep */
  620.     for (i = 0; i < 7; i++)
  621.     {
  622.         if (strncmp(MyDay, NameOfday[i], 3) == 0)
  623.         {
  624.             break;
  625.         }
  626.     }
  627.     MyTime.nYear = systime.wYear;
  628.     MyTime.nMonth = (U8) systime.wMonth;
  629.     MyTime.nDay = (U8) systime.wDay;
  630.     MyTime.nHour = (U8) systime.wHour;
  631.     MyTime.nMin = (U8) systime.wMinute;
  632.     MyTime.nSec = (U8) systime.wSecond;
  633.     MyTime.DayIndex = (U8) i;
  634.     sprintf(
  635.         DateTimeStrings[0],
  636.         "%s  %02d %s  %d",
  637.         NameOfday[MyTime.DayIndex],
  638.         MyTime.nDay,
  639.         NameOfMonth[MyTime.nMonth - 1],
  640.         MyTime.nYear);
  641.     //sprintf(DateTimeStrings[1],"%02d::%02d::%02d",MyTime.nHour,MyTime.nMin,MyTime.nSec);
  642.     //sprintf(DateTimeStrings[1],"%02d:%02d",MyTime.nHour,MyTime.nMin);
  643.     StartTimer(TIMER_REAL_TIME_CLOCK, 1000, DateTimerProc);
  644. #else 
  645.     MyTime.nYear += DT_MIN_YEAR;
  646.     StartTimer(TIMER_REAL_TIME_CLOCK, 1000, DateTimerProc);
  647. #endif 
  648. }
  649. /*****************************************************************************
  650.  * FUNCTION
  651.  *  GetDateTime
  652.  * DESCRIPTION
  653.  *  Function to get the current date and time.
  654.  * PARAMETERS
  655.  *  t       [IN/OUT]        Variable to store the result.
  656.  * RETURNS
  657.  *  void
  658.  *****************************************************************************/
  659. void GetDateTime(MYTIME *t)
  660. {
  661. #ifdef __MTK_TARGET__
  662.     /*----------------------------------------------------------------*/
  663.     /* Local Variables                                                */
  664.     /*----------------------------------------------------------------*/
  665.     /*----------------------------------------------------------------*/
  666.     /* Code Body                                                      */
  667.     /*----------------------------------------------------------------*/
  668.     t->nSec = gclockData.rtc_sec;
  669.     t->nMin = gclockData.rtc_min;
  670.     t->nHour = gclockData.rtc_hour;
  671.     t->nDay = gclockData.rtc_day;
  672.     t->nMonth = gclockData.rtc_mon;
  673.     t->DayIndex = gclockData.rtc_wday;
  674.     t->nYear = YEARFORMATE + gclockData.rtc_year;
  675. #else /* __MTK_TARGET__ */ 
  676.     t->DayIndex = MyTime.DayIndex;
  677.     t->nDay = MyTime.nDay;
  678.     t->nHour = MyTime.nHour;
  679.     t->nMin = MyTime.nMin;
  680.     t->nSec = MyTime.nSec;
  681.     t->nMonth = MyTime.nMonth;
  682.     t->nYear = MyTime.nYear;
  683. #endif /* __MTK_TARGET__ */ 
  684.     t->DayIndex = DOW(t->nYear, t->nMonth, t->nDay);
  685. }
  686. /*****************************************************************************
  687.  * FUNCTION
  688.  *  DOW
  689.  * DESCRIPTION
  690.  *  Function to compute current day of week.
  691.  * PARAMETERS
  692.  *  y       [IN]        Year of the date to be computed. (example, 2004)
  693.  *  m       [IN]        Month of the date to be computed
  694.  *  d       [IN]        Day of the date to be computed
  695.  * RETURNS
  696.  *  U8 index of day of week
  697.  *****************************************************************************/
  698. U8 DOW(U16 y, U8 m, U8 d)
  699. {
  700.     /*----------------------------------------------------------------*/
  701.     /* Local Variables                                                */
  702.     /*----------------------------------------------------------------*/
  703.     /*----------------------------------------------------------------*/
  704.     /* Code Body                                                      */
  705.     /*----------------------------------------------------------------*/
  706.     if (m < 3)
  707.     {
  708.         m += 13;
  709.         y--;
  710.     }
  711.     else
  712.     {
  713.         m++;
  714.     }
  715.     return (d + 26 * m / 10 + y + y / 4 - y / 100 + y / 400 + 6) % 7;
  716. }
  717. /*****************************************************************************
  718.  * FUNCTION
  719.  *  IsLeapYear
  720.  * DOW
  721.  * DESCRIPTION
  722.  *  Function to find out if given year is a leap year
  723.  * PARAMETERS
  724.  *  year        [IN]        
  725.  *  y(?)        [IN]        Year of the date to be computed  (example, 2004)(?)
  726.  * RETURNS
  727.  *  1 if the year is leap; otherwise 0.
  728.  *****************************************************************************/
  729. U16 IsLeapYear(U16 year)
  730. {
  731.     /*----------------------------------------------------------------*/
  732.     /* Local Variables                                                */
  733.     /*----------------------------------------------------------------*/
  734.     /*----------------------------------------------------------------*/
  735.     /* Code Body                                                      */
  736.     /*----------------------------------------------------------------*/
  737.     if ((year % 400) == 0)
  738.     {
  739.         return 1;
  740.     }
  741.     else if ((year % 100) == 0)
  742.     {
  743.         return 0;
  744.     }
  745.     else if ((year % 4) == 0)
  746.     {
  747.         return 1;
  748.     }
  749.     else
  750.     {
  751.         return 0;
  752.     }
  753. }
  754. /*****************************************************************************
  755.  * FUNCTION
  756.  *  GetTimeDifference
  757.  * DESCRIPTION
  758.  *  Function to calculate the difference between 2 times.
  759.  * PARAMETERS
  760.  *  t1          [IN]            The target time
  761.  *  t2          [IN]            The base time  (t1 shall be greater than t2)
  762.  *  result      [IN/OUT]        Result of t1-t2
  763.  * RETURNS
  764.  *  NULL if t1 < t2; otherwise, return result
  765.  *****************************************************************************/
  766. MYTIME *GetTimeDifference(MYTIME *t1, MYTIME *t2, MYTIME *result)
  767. {
  768.     /*----------------------------------------------------------------*/
  769.     /* Local Variables                                                */
  770.     /*----------------------------------------------------------------*/
  771.     /*----------------------------------------------------------------*/
  772.     /* Code Body                                                      */
  773.     /*----------------------------------------------------------------*/
  774.     /* Validate year ..no need of validating for month .. */
  775.     /* /Handled NULL  changes by Kuldeep for Network Simulator 2.0 */
  776.     if (NULL == t2)
  777.     {
  778.         return NULL;
  779.     }
  780.     /* /Handled NULL  changes by Kuldeep */
  781.     if (t1->nYear < t2->nYear)
  782.     {
  783.         return NULL;
  784.     }
  785.     else
  786.     {
  787.         DecrementTime2(*t1, *t2, result);
  788.         return result;
  789.     }
  790. }
  791. /*****************************************************************************
  792.  * FUNCTION
  793.  *  FindMaxTime
  794.  * DESCRIPTION
  795.  *  Function to find the larger one between two times
  796.  * PARAMETERS
  797.  *  t1      [IN]        The first time to be compared.
  798.  *  t2      [IN]        The second time to be compared.
  799.  * RETURNS
  800.  *  0 if t1 < t2; otherwise 1.
  801.  *****************************************************************************/
  802. U16 FindMaxTime(MYTIME *t1, MYTIME *t2)
  803. {
  804.     /*----------------------------------------------------------------*/
  805.     /* Local Variables                                                */
  806.     /*----------------------------------------------------------------*/
  807.     /*----------------------------------------------------------------*/
  808.     /* Code Body                                                      */
  809.     /*----------------------------------------------------------------*/
  810.     if (t1->nYear == t2->nYear)
  811.     {
  812.         if (t1->nMonth == t2->nMonth)
  813.         {
  814.             if (t1->nDay == t2->nDay)
  815.             {
  816.                 if (t1->nHour == t2->nHour)
  817.                 {
  818.                     if (t1->nMin == t2->nMin)
  819.                     {
  820.                         if (t1->nSec >= t2->nSec)
  821.                         {
  822.                             return 1;
  823.                         }
  824.                         else
  825.                         {
  826.                             return 0;
  827.                         }
  828.                     }
  829.                     else if (t1->nMin > t2->nMin)
  830.                     {
  831.                         return 1;
  832.                     }
  833.                     else
  834.                     {
  835.                         return 0;
  836.                     }
  837.                 }
  838.                 else if (t1->nHour > t2->nHour)
  839.                 {
  840.                     return 1;
  841.                 }
  842.                 else
  843.                 {
  844.                     return 0;
  845.                 }
  846.             }
  847.             else if (t1->nDay > t2->nDay)
  848.             {
  849.                 return 1;
  850.             }
  851.             else
  852.             {
  853.                 return 0;
  854.             }
  855.         }
  856.         else if (t1->nMonth > t2->nMonth)
  857.         {
  858.             return 1;
  859.         }
  860.         else
  861.         {
  862.             return 0;
  863.         }
  864.     }
  865.     else if (t1->nYear > t2->nYear)
  866.     {
  867.         return 1;
  868.     }
  869.     else
  870.     {
  871.         return 0;
  872.     }
  873. }
  874. /*****************************************************************************
  875.  * FUNCTION
  876.  *  DecrementTime2
  877.  * DESCRIPTION
  878.  *  Decrease a reference time by some time.
  879.  *  The difference between DecrementTime is the result may not be a "time"
  880.  *  Because it's just to get the "difference", the time may be 1 month, 0 day, 12 minutes
  881.  * PARAMETERS
  882.  *  timeToDecrement     [IN]            Time to be decreased
  883.  *  decrement           [IN]            Time to decrease
  884.  *  Result              [IN/OUT]        Result of compuatation
  885.  * RETURNS
  886.  *  void
  887.  *****************************************************************************/
  888. void DecrementTime2(MYTIME timeToDecrement, MYTIME decrement, MYTIME *Result)
  889. {
  890.     /*----------------------------------------------------------------*/
  891.     /* Local Variables                                                */
  892.     /*----------------------------------------------------------------*/
  893.     /*----------------------------------------------------------------*/
  894.     /* Code Body                                                      */
  895.     /*----------------------------------------------------------------*/
  896.     if (decrement.nSec != 0)
  897.     {
  898.         if (timeToDecrement.nSec >= decrement.nSec)
  899.         {
  900.             Result->nSec = timeToDecrement.nSec - decrement.nSec;
  901.         }
  902.         else
  903.         {
  904.             Result->nSec = NUM_MIN_HR + timeToDecrement.nSec - decrement.nSec;
  905.             decrement.nMin++;
  906.         }
  907.     }
  908.     else
  909.     {
  910.         Result->nSec = timeToDecrement.nSec;
  911.     }
  912.     if (decrement.nMin != 0)
  913.     {
  914.         if (timeToDecrement.nMin >= decrement.nMin)
  915.         {
  916.             Result->nMin = timeToDecrement.nMin - decrement.nMin;
  917.         }
  918.         else
  919.         {
  920.             Result->nMin = NUM_MIN_HR + timeToDecrement.nMin - decrement.nMin;
  921.             decrement.nHour++;
  922.         }
  923.     }
  924.     else
  925.     {
  926.         Result->nMin = timeToDecrement.nMin;
  927.     }
  928.     if (decrement.nHour != 0)
  929.     {
  930.         if (timeToDecrement.nHour >= decrement.nHour)
  931.         {
  932.             Result->nHour = timeToDecrement.nHour - decrement.nHour;
  933.         }
  934.         else
  935.         {
  936.             Result->nHour = NUM_HRS_DAY + timeToDecrement.nHour - decrement.nHour;
  937.             decrement.nDay++;
  938.         }
  939.     }
  940.     else
  941.     {
  942.         Result->nHour = timeToDecrement.nHour;
  943.     }
  944.     if (decrement.nDay != 0)
  945.     {
  946.         if (timeToDecrement.nDay >= decrement.nDay)
  947.         {
  948.             Result->nDay = timeToDecrement.nDay - decrement.nDay;
  949.         }
  950.         else
  951.         {
  952.             U8 tmp_last_day;
  953.             decrement.nMonth++;
  954.             if (timeToDecrement.nMonth != JAN)
  955.             {
  956.                 tmp_last_day = LastDayOfMonth((U8) (timeToDecrement.nMonth - 1), timeToDecrement.nYear);
  957.             }
  958.             else
  959.             {
  960.                 tmp_last_day = 31;
  961.             }
  962.             if (tmp_last_day < (tmp_last_day + timeToDecrement.nDay - decrement.nDay))
  963.             {
  964.                 if (DEC == timeToDecrement.nMonth)
  965.                 {
  966.                     tmp_last_day += 31;
  967.                 }
  968.                 else
  969.                 {
  970.                     tmp_last_day += LastDayOfMonth((U8) (timeToDecrement.nMonth), timeToDecrement.nYear);
  971.                 }
  972.                 decrement.nMonth++;
  973.             }
  974.             Result->nDay = tmp_last_day + timeToDecrement.nDay - decrement.nDay;
  975.         }
  976.     }
  977.     else
  978.     {
  979.         Result->nDay = timeToDecrement.nDay;
  980.     }
  981.     if (decrement.nMonth != 0)
  982.     {
  983.         if (timeToDecrement.nMonth >= decrement.nMonth)
  984.         {
  985.             Result->nMonth = timeToDecrement.nMonth - decrement.nMonth;
  986.         }
  987.         else
  988.         {
  989.             Result->nMonth = NUM_MONTHS + timeToDecrement.nMonth - decrement.nMonth;
  990.             decrement.nYear++;
  991.         }
  992.     }
  993.     else
  994.     {
  995.         Result->nMonth = timeToDecrement.nMonth;
  996.     }
  997.     Result->nYear = timeToDecrement.nYear - decrement.nYear;
  998.     Result->DayIndex = DOW(Result->nYear, Result->nMonth, Result->nDay);
  999. }
  1000. /*****************************************************************************
  1001.  * FUNCTION
  1002.  *  DecrementTime
  1003.  * DESCRIPTION
  1004.  *  Decrease a reference time by some time
  1005.  * PARAMETERS
  1006.  *  timeToDecrement     [IN]            Time to be decreased
  1007.  *  decrement           [IN]            Time to decrease
  1008.  *  Result              [IN/OUT]        Result of compuatation
  1009.  * RETURNS
  1010.  *  void
  1011.  *****************************************************************************/
  1012. void DecrementTime(MYTIME timeToDecrement, MYTIME decrement, MYTIME *Result)
  1013. {
  1014.     /*----------------------------------------------------------------*/
  1015.     /* Local Variables                                                */
  1016.     /*----------------------------------------------------------------*/
  1017.     /*----------------------------------------------------------------*/
  1018.     /* Code Body                                                      */
  1019.     /*----------------------------------------------------------------*/
  1020.     if (decrement.nSec != 0)
  1021.     {
  1022.         if (timeToDecrement.nSec >= decrement.nSec)
  1023.         {
  1024.             Result->nSec = timeToDecrement.nSec - decrement.nSec;
  1025.         }
  1026.         else
  1027.         {
  1028.             Result->nSec = NUM_MIN_HR + timeToDecrement.nSec - decrement.nSec;
  1029.             decrement.nMin++;
  1030.         }
  1031.     }
  1032.     else
  1033.     {
  1034.         Result->nSec = timeToDecrement.nSec;
  1035.     }
  1036.     if (decrement.nMin != 0)
  1037.     {
  1038.         if (timeToDecrement.nMin >= decrement.nMin)
  1039.         {
  1040.             Result->nMin = timeToDecrement.nMin - decrement.nMin;
  1041.         }
  1042.         else
  1043.         {
  1044.             Result->nMin = NUM_MIN_HR + timeToDecrement.nMin - decrement.nMin;
  1045.             decrement.nHour++;
  1046.         }
  1047.     }
  1048.     else
  1049.     {
  1050.         Result->nMin = timeToDecrement.nMin;
  1051.     }
  1052.     if (decrement.nHour != 0)
  1053.     {
  1054.         if (timeToDecrement.nHour >= decrement.nHour)
  1055.         {
  1056.             Result->nHour = timeToDecrement.nHour - decrement.nHour;
  1057.         }
  1058.         else
  1059.         {
  1060.             Result->nHour = NUM_HRS_DAY + timeToDecrement.nHour - decrement.nHour;
  1061.             decrement.nDay++;
  1062.         }
  1063.     }
  1064.     else
  1065.     {
  1066.         Result->nHour = timeToDecrement.nHour;
  1067.     }
  1068.     if (decrement.nDay != 0)
  1069.     {
  1070.         if (timeToDecrement.nDay > decrement.nDay)
  1071.         {
  1072.             Result->nDay = timeToDecrement.nDay - decrement.nDay;
  1073.         }
  1074.         else
  1075.         {
  1076.             decrement.nMonth++;
  1077.             if (timeToDecrement.nMonth != JAN)
  1078.             {
  1079.                 Result->nDay = LastDayOfMonth(
  1080.                                 (U8) (timeToDecrement.nMonth - 1),
  1081.                                 timeToDecrement.nYear) + timeToDecrement.nDay - decrement.nDay;
  1082.             }
  1083.             else
  1084.             {
  1085.                 Result->nDay = 31 + timeToDecrement.nDay - decrement.nDay;
  1086.             }
  1087.         }
  1088.     }
  1089.     else
  1090.     {
  1091.         Result->nDay = timeToDecrement.nDay;
  1092.     }
  1093.     if (decrement.nMonth != 0)
  1094.     {
  1095.         if (timeToDecrement.nMonth > decrement.nMonth)
  1096.         {
  1097.             Result->nMonth = timeToDecrement.nMonth - decrement.nMonth;
  1098.         }
  1099.         else
  1100.         {
  1101.             Result->nMonth = NUM_MONTHS + timeToDecrement.nMonth - decrement.nMonth;
  1102.             decrement.nYear++;
  1103.         }
  1104.     }
  1105.     else
  1106.     {
  1107.         Result->nMonth = timeToDecrement.nMonth;
  1108.     }
  1109.     Result->nYear = timeToDecrement.nYear - decrement.nYear;
  1110.     Result->DayIndex = DOW(Result->nYear, Result->nMonth, Result->nDay);
  1111. }
  1112. /*****************************************************************************
  1113.  * FUNCTION
  1114.  *  DTGetRTCTime
  1115.  * DESCRIPTION
  1116.  *  Get current RTC time of system.
  1117.  * PARAMETERS
  1118.  *  t       [IN/OUT]        Variable to store current time.
  1119.  * RETURNS
  1120.  *  void
  1121.  *****************************************************************************/
  1122. void DTGetRTCTime(MYTIME *t)
  1123. {
  1124. #ifdef __MTK_TARGET__
  1125.     /*----------------------------------------------------------------*/
  1126.     /* Local Variables                                                */
  1127.     /*----------------------------------------------------------------*/
  1128.     t_rtc rtc_time;
  1129.     /*----------------------------------------------------------------*/
  1130.     /* Code Body                                                      */
  1131.     /*----------------------------------------------------------------*/
  1132.     RTC_GetTime(&rtc_time);
  1133.     t->nYear = rtc_time.rtc_year + YEARFORMATE;
  1134.     t->nMonth = rtc_time.rtc_mon;
  1135.     t->nDay = rtc_time.rtc_day;
  1136.     t->nHour = rtc_time.rtc_hour;
  1137.     t->nMin = rtc_time.rtc_min;
  1138.     t->nSec = rtc_time.rtc_sec;
  1139.     t->DayIndex = DOW(t->nYear, t->nMonth, t->nDay);
  1140. #else /* __MTK_TARGET__ */ 
  1141.     GetDateTime(&(*t));
  1142. #endif /* __MTK_TARGET__ */ 
  1143. }
  1144. /*****************************************************************************
  1145.  * FUNCTION
  1146.  *  CompareTime
  1147.  * DESCRIPTION
  1148.  *  Compare the equality between 2 times.
  1149.  * PARAMETERS
  1150.  *  referenceTime       [IN]        Time to be compare in right-hand side
  1151.  *  compareTime         [IN]        Time to be compare in left-hand side
  1152.  *  diff                [IN]        Not yet used
  1153.  * RETURNS
  1154.  *  TIME_LESS      if referenceTime < compareTime
  1155.  *  TIME_EQUAL     if referenceTime = compareTime
  1156.  *  TIME_GREATER   if referenceTime > compareTime
  1157.  *****************************************************************************/
  1158. TIME_EQUALITY CompareTime(MYTIME referenceTime, MYTIME compareTime, MYTIME *diff)
  1159. {
  1160.     /*----------------------------------------------------------------*/
  1161.     /* Local Variables                                                */
  1162.     /*----------------------------------------------------------------*/
  1163.     TIME_EQUALITY toReturn;
  1164.     /*----------------------------------------------------------------*/
  1165.     /* Code Body                                                      */
  1166.     /*----------------------------------------------------------------*/
  1167.     if (referenceTime.nYear == compareTime.nYear)
  1168.     {
  1169.         if (referenceTime.nMonth == compareTime.nMonth)
  1170.         {
  1171.             if (referenceTime.nDay == compareTime.nDay)
  1172.             {
  1173.                 if (referenceTime.nHour == compareTime.nHour)
  1174.                 {
  1175.                     if (referenceTime.nMin == compareTime.nMin)
  1176.                     {
  1177.                         if (referenceTime.nSec == compareTime.nSec)
  1178.                         {
  1179.                             toReturn = TIME_EQUAL;
  1180.                         }
  1181.                         else
  1182.                         {
  1183.                             if (referenceTime.nSec < compareTime.nSec)
  1184.                             {
  1185.                                 toReturn = TIME_LESS;
  1186.                             }
  1187.                             else
  1188.                             {
  1189.                                 toReturn = TIME_GREATER;
  1190.                             }
  1191.                         }
  1192.                     }
  1193.                     else
  1194.                     {
  1195.                         if (referenceTime.nMin < compareTime.nMin)
  1196.                         {
  1197.                             toReturn = TIME_LESS;
  1198.                         }
  1199.                         else
  1200.                         {
  1201.                             toReturn = TIME_GREATER;
  1202.                         }
  1203.                     }
  1204.                 }
  1205.                 else
  1206.                 {
  1207.                     if (referenceTime.nHour < compareTime.nHour)
  1208.                     {
  1209.                         toReturn = TIME_LESS;
  1210.                     }
  1211.                     else
  1212.                     {
  1213.                         toReturn = TIME_GREATER;
  1214.                     }
  1215.                 }
  1216.             }
  1217.             else
  1218.             {
  1219.                 if (referenceTime.nDay < compareTime.nDay)
  1220.                 {
  1221.                     toReturn = TIME_LESS;
  1222.                 }
  1223.                 else
  1224.                 {
  1225.                     toReturn = TIME_GREATER;
  1226.                 }
  1227.             }
  1228.         }
  1229.         else
  1230.         {
  1231.             if (referenceTime.nMonth < compareTime.nMonth)
  1232.             {
  1233.                 toReturn = TIME_LESS;
  1234.             }
  1235.             else
  1236.             {
  1237.                 toReturn = TIME_GREATER;
  1238.             }
  1239.         }
  1240.     }
  1241.     else
  1242.     {
  1243.         if (referenceTime.nYear < compareTime.nYear)
  1244.         {
  1245.             toReturn = TIME_LESS;
  1246.         }
  1247.         else
  1248.         {
  1249.             toReturn = TIME_GREATER;
  1250.         }
  1251.     }
  1252.     return toReturn;
  1253. }
  1254. /*****************************************************************************
  1255.  * FUNCTION
  1256.  *  mmi_dt_is_valid
  1257.  * DESCRIPTION
  1258.  *  To compute is the date/time is within reasonable range
  1259.  * PARAMETERS
  1260.  *  t       [?]     [?]     Time to be computed
  1261.  * RETURNS
  1262.  *  TURE if date/time valid; otherwise, FALSE
  1263.  *****************************************************************************/
  1264. U8 mmi_dt_is_valid(MYTIME *t)
  1265. {
  1266.     /*----------------------------------------------------------------*/
  1267.     /* Local Variables                                                */
  1268.     /*----------------------------------------------------------------*/
  1269.     /*----------------------------------------------------------------*/
  1270.     /* Code Body                                                      */
  1271.     /*----------------------------------------------------------------*/
  1272.     /* error handling */
  1273.     if (t->nYear > 2030 || t->nYear < YEARFORMATE)
  1274.     {
  1275.         return FALSE;
  1276.     }
  1277.     if (t->nMonth > 12)
  1278.     {
  1279.         return FALSE;
  1280.     }
  1281.     if (t->nMonth == 2)
  1282.     {
  1283.         if (t->nDay > (gDaysInMonth[t->nMonth - 1] + IsLeapYear(t->nYear)))
  1284.         {
  1285.             return FALSE;
  1286.         }
  1287.     }
  1288.     else
  1289.     {
  1290.         if (t->nDay > gDaysInMonth[t->nMonth - 1])
  1291.         {
  1292.             return FALSE;
  1293.         }
  1294.     }
  1295.     if (t->nHour > 23)
  1296.     {
  1297.         return FALSE;
  1298.     }
  1299.     if (t->nMin > 59)
  1300.     {
  1301.         return FALSE;
  1302.     }
  1303.     if (t->nSec > 59)
  1304.     {
  1305.         return FALSE;
  1306.     }
  1307.     return TRUE;
  1308. }
  1309. /*****************************************************************************
  1310.  * FUNCTION
  1311.  *  mmi_conv_tz_to_mytime
  1312.  * DESCRIPTION
  1313.  *  contert timezone to MYTIME structure
  1314.  * PARAMETERS
  1315.  *  tz      [IN]        Time zone to be converted
  1316.  * RETURNS
  1317.  *  result in MYTIME structure
  1318.  *****************************************************************************/
  1319. MYTIME mmi_conv_tz_to_mytime(FLOAT tz)
  1320. {
  1321.     /*----------------------------------------------------------------*/
  1322.     /* Local Variables                                                */
  1323.     /*----------------------------------------------------------------*/
  1324.     MYTIME result;
  1325.     S16 timezone = (S16) (tz * 4);
  1326.     /*----------------------------------------------------------------*/
  1327.     /* Code Body                                                      */
  1328.     /*----------------------------------------------------------------*/
  1329.     memset(&result, 0, sizeof(MYTIME));
  1330.     result.nHour = (U8) (timezone / 4);
  1331.     result.nMin = (U8) ((timezone % 4) * 15);
  1332.     return result;
  1333. }
  1334. /*****************************************************************************
  1335.  * FUNCTION
  1336.  *  mmi_dt_utc_to_rtc
  1337.  * DESCRIPTION
  1338.  *  compute utc time to rtc time
  1339.  * PARAMETERS
  1340.  *  tz      [IN]        Time zone
  1341.  *  utc     [IN]        Utc time
  1342.  * RETURNS
  1343.  *  result of time
  1344.  *****************************************************************************/
  1345. MYTIME mmi_dt_utc_to_rtc(FLOAT tz, MYTIME utc)
  1346. {
  1347.     /*----------------------------------------------------------------*/
  1348.     /* Local Variables                                                */
  1349.     /*----------------------------------------------------------------*/
  1350.     MYTIME result;
  1351.     MYTIME incTime;
  1352.     U8 negative = FALSE;
  1353.     /*----------------------------------------------------------------*/
  1354.     /* Code Body                                                      */
  1355.     /*----------------------------------------------------------------*/
  1356.     if (tz < 0)
  1357.     {
  1358.         negative = TRUE;
  1359.         tz = 0 - tz;
  1360.     }
  1361.     incTime = mmi_conv_tz_to_mytime(tz);
  1362.     if (negative)
  1363.     {
  1364.         DecrementTime(utc, incTime, &result);
  1365.     }
  1366.     else
  1367.     {
  1368.         IncrementTime(utc, incTime, &result);
  1369.     }
  1370.     return result;
  1371. }
  1372. /*****************************************************************************
  1373.  * FUNCTION
  1374.  *  LastDayOfMonth
  1375.  * DESCRIPTION
  1376.  *  Function to find the last day of specific month.
  1377.  * PARAMETERS
  1378.  *  month       [IN]        Month
  1379.  *  year        [IN]        Year
  1380.  * RETURNS
  1381.  *  number of days
  1382.  *****************************************************************************/
  1383. U8 LastDayOfMonth(U8 month, U16 year)
  1384. {
  1385.     /*----------------------------------------------------------------*/
  1386.     /* Local Variables                                                */
  1387.     /*----------------------------------------------------------------*/
  1388.     /*----------------------------------------------------------------*/
  1389.     /* Code Body                                                      */
  1390.     /*----------------------------------------------------------------*/
  1391.     if (month != FEB)
  1392.     {
  1393.         return gDaysInMonth[month - 1];
  1394.     }
  1395.     else
  1396.     {
  1397.         return gDaysInMonth[1] + IsLeapYear(year);
  1398.     }
  1399. }
  1400. /*****************************************************************************
  1401.  * FUNCTION
  1402.  *  IncrementTime
  1403.  * DESCRIPTION
  1404.  *  Increase a reference time by some time
  1405.  * PARAMETERS
  1406.  *  timeToIncrement     [IN]        Time to be increased
  1407.  *  increment           [IN]        
  1408.  *  Result              [IN]        
  1409.  *  decrement(?)        [IN]        Time to increase(?)
  1410.  * RETURNS
  1411.  *  result of computation(?)
  1412.  *****************************************************************************/
  1413. void IncrementTime(MYTIME timeToIncrement, MYTIME increment, MYTIME *Result)
  1414. {
  1415.     /*----------------------------------------------------------------*/
  1416.     /* Local Variables                                                */
  1417.     /*----------------------------------------------------------------*/
  1418.     S16 NumOfDays;
  1419.     /*----------------------------------------------------------------*/
  1420.     /* Code Body                                                      */
  1421.     /*----------------------------------------------------------------*/
  1422.     /* second */
  1423.     Result->nSec = (timeToIncrement.nSec + increment.nSec);
  1424.     /* minute */
  1425.     Result->nMin = (timeToIncrement.nMin + increment.nMin);
  1426.     if (Result->nSec >= NUM_MIN_HR)
  1427.     {
  1428.         Result->nSec -= NUM_MIN_HR;
  1429.         Result->nMin += 1;
  1430.     }
  1431.     /* hour */
  1432.     Result->nHour = (timeToIncrement.nHour + increment.nHour);
  1433.     if (Result->nMin >= NUM_MIN_HR)
  1434.     {
  1435.         Result->nMin -= NUM_MIN_HR;
  1436.         Result->nHour += 1;
  1437.     }
  1438.     /* day */
  1439.     Result->nDay = (timeToIncrement.nDay + increment.nDay);
  1440.     if (Result->nHour >= NUM_HRS_DAY)
  1441.     {
  1442.         Result->nHour -= NUM_HRS_DAY;
  1443.         Result->nDay += +1;
  1444.     }
  1445.     /* month, year */
  1446.     Result->nMonth = timeToIncrement.nMonth + increment.nMonth;
  1447.     Result->nYear = timeToIncrement.nYear + increment.nYear;
  1448.     if (Result->nMonth > NUM_MONTHS)
  1449.     {
  1450.         Result->nMonth -= NUM_MONTHS;
  1451.         Result->nYear++;
  1452.     }
  1453.     /* correct day */
  1454.     NumOfDays = LastDayOfMonth(timeToIncrement.nMonth, timeToIncrement.nYear);
  1455.     if (Result->nDay > NumOfDays)
  1456.     {
  1457.         Result->nDay -= NumOfDays;
  1458.         if (Result->nMonth != DEC)
  1459.         {
  1460.             Result->nMonth += 1;
  1461.         }
  1462.         else
  1463.         {
  1464.             Result->nMonth = JAN;
  1465.             Result->nYear += 1;
  1466.         }
  1467.     }
  1468.     Result->DayIndex = DOW(Result->nYear, Result->nMonth, Result->nDay);
  1469. }
  1470. /*****************************************************************************
  1471.  * FUNCTION
  1472.  *  applib_dt_get_rtc_without_daylight_impact
  1473.  * DESCRIPTION
  1474.  *  
  1475.  * PARAMETERS
  1476.  *  t       [?]     
  1477.  * RETURNS
  1478.  *  void
  1479.  *****************************************************************************/
  1480. void applib_dt_get_rtc_without_daylight_impact(MYTIME *t)
  1481. {
  1482.     /*----------------------------------------------------------------*/
  1483.     /* Local Variables                                                */
  1484.     /*----------------------------------------------------------------*/
  1485.     kal_uint8 dst;
  1486.     MYTIME decreaseDST;
  1487. S16 error;
  1488.     /*----------------------------------------------------------------*/
  1489.     /* Code Body                                                      */
  1490.     /*----------------------------------------------------------------*/
  1491.     DTGetRTCTime((MYTIME*)t);
  1492. ReadValue(NVRAM_SETTING_DT_DST, &dst, DS_BYTE, &error);
  1493.     if (dst)
  1494.     {
  1495.         memset(&decreaseDST, 0, sizeof(MYTIME));
  1496.         decreaseDST.nHour = 1;
  1497.         DecrementTime(*t, decreaseDST, t);
  1498.     }
  1499. }
  1500. /*****************************************************************************
  1501.  * FUNCTION
  1502.  *  applib_dt_modify_dt_with_daylight_impact
  1503.  * DESCRIPTION
  1504.  *  
  1505.  * PARAMETERS
  1506.  *  t       [?]     
  1507.  * RETURNS
  1508.  *  void
  1509.  *****************************************************************************/
  1510. void applib_dt_modify_dt_with_daylight_impact(MYTIME *t)
  1511. {
  1512.     /*----------------------------------------------------------------*/
  1513.     /* Local Variables                                                */
  1514.     /*----------------------------------------------------------------*/
  1515.     kal_uint8 dst;
  1516.     MYTIME increaseDST;
  1517. S16 error;
  1518.     /*----------------------------------------------------------------*/
  1519.     /* Code Body                                                      */
  1520.     /*----------------------------------------------------------------*/
  1521.     ReadValue(NVRAM_SETTING_DT_DST, &dst, DS_BYTE, &error);
  1522.     if (dst)
  1523.     {
  1524.         memset(&increaseDST, 0, sizeof(MYTIME));
  1525.         increaseDST.nHour = 1;
  1526.         IncrementTime(*t, increaseDST, t);
  1527.     }
  1528. }
  1529. /*****************************************************************************
  1530.  * FUNCTION
  1531.  *  mmi_dt_mytime_2_utc_sec
  1532.  * DESCRIPTION
  1533.  *  convert MYTIME format of time to seconds after 1970/1/1
  1534.  * PARAMETERS
  1535.  *  currTime        [?]     
  1536.  * RETURNS
  1537.  *  void
  1538.  *****************************************************************************/
  1539. kal_int32 mmi_dt_mytime_2_utc_sec(MYTIME *currTime, kal_bool daylightSaving)
  1540. {
  1541.     /*----------------------------------------------------------------*/
  1542.     /* Local Variables                                                */
  1543.     /*----------------------------------------------------------------*/
  1544.     kal_uint16 i;
  1545.     kal_uint32 no_of_days = 0;
  1546.     kal_int32 utc_time;
  1547.     kal_int32 is_leap;
  1548.     kal_uint8 dst;
  1549.     S16 error;
  1550.     /*----------------------------------------------------------------*/
  1551.     /* Code Body                                                      */
  1552.     /*----------------------------------------------------------------*/
  1553.     if (currTime->nYear < DT_UTC_BASE_YEAR)
  1554.     {
  1555.         return 0;
  1556.     }
  1557.     /* year */
  1558.     for (i = DT_UTC_BASE_YEAR; i < currTime->nYear; i++)
  1559.     {
  1560.         no_of_days += (365 + IsLeapYear(i));
  1561.     }
  1562.     /* month */
  1563.     is_leap = IsLeapYear(currTime->nYear);
  1564.     for (i = 1; i < currTime->nMonth; i++)
  1565.     {
  1566.         no_of_days += LastDayOfMonth((kal_uint8) i, currTime->nYear);
  1567.     }
  1568.     /* day */
  1569.     no_of_days += (currTime->nDay - 1);
  1570.     /* sec */
  1571.     utc_time =
  1572.         (kal_uint32) no_of_days *DT_SEC_PER_DAY + (kal_uint32) (currTime->nHour * DT_SEC_PER_HOUR +
  1573.                                                                 currTime->nMin * DT_SEC_PER_MIN + currTime->nSec);
  1574.                                                                 
  1575. ReadValue(NVRAM_SETTING_DT_DST, &dst, DS_BYTE, &error);
  1576. if (dst && daylightSaving)
  1577.     {
  1578.         utc_time -= DT_SEC_PER_HOUR;
  1579.     }
  1580.     
  1581.     return utc_time;
  1582. }
  1583. /*****************************************************************************
  1584.  * FUNCTION
  1585.  *  mmi_dt_utc_sec_2_mytime
  1586.  * DESCRIPTION
  1587.  *  convert from UTC second to MYTIME struct
  1588.  * PARAMETERS
  1589.  *  utc_sec     [IN]        Uct_sec
  1590.  *  result      [IN]        Result of time
  1591.  * RETURNS
  1592.  *  TRUE if success; otherwise, FALSE.
  1593.  *****************************************************************************/
  1594. kal_uint8 mmi_dt_utc_sec_2_mytime(kal_int32 utc_sec, MYTIME *result, kal_bool daylightSaving)
  1595. {
  1596.     /*----------------------------------------------------------------*/
  1597.     /* Local Variables                                                */
  1598.     /*----------------------------------------------------------------*/
  1599.     kal_int32 sec, day;
  1600.     kal_uint16 y;
  1601.     kal_uint8 m;
  1602.     kal_uint16 d;
  1603.     kal_uint8 dst;
  1604.     S16 error;
  1605.     /*----------------------------------------------------------------*/
  1606.     /* Code Body                                                      */
  1607.     /*----------------------------------------------------------------*/
  1608.     if (utc_sec < 0)
  1609.     {
  1610.         return KAL_FALSE;
  1611.     }
  1612.     ReadValue(NVRAM_SETTING_DT_DST, &dst, DS_BYTE, &error);
  1613.     if (dst && daylightSaving)
  1614.     {
  1615.         utc_sec += DT_SEC_PER_HOUR;
  1616.     }
  1617.     /* hour, min, sec */
  1618.     /* hour */
  1619.     sec = utc_sec % DT_SEC_PER_DAY;
  1620.     result->nHour = sec / DT_SEC_PER_HOUR;
  1621.     /* min */
  1622.     sec %= DT_SEC_PER_HOUR;
  1623.     result->nMin = sec / DT_SEC_PER_MIN;
  1624.     /* sec */
  1625.     result->nSec = sec % DT_SEC_PER_MIN;
  1626.     /* year, month, day */
  1627.     /* year */
  1628.     /* year */
  1629.     day = utc_sec / DT_SEC_PER_DAY;
  1630.     for (y = DT_UTC_BASE_YEAR; day > 0; y++)
  1631.     {
  1632.         d = (DT_DAY_PER_YEAR + IsLeapYear(y));
  1633.         if (day >= d)
  1634.         {
  1635.             day -= d;
  1636.         }
  1637.         else
  1638.         {
  1639.             break;
  1640.         }
  1641.     }
  1642.     result->nYear = y;
  1643.     for (m = 1; m < DT_MONTH_PER_YEAR; m++)
  1644.     {
  1645.         d = LastDayOfMonth(m, y);
  1646.         if (day >= d)
  1647.         {
  1648.             day -= d;
  1649.         }
  1650.         else
  1651.         {
  1652.             break;
  1653.         }
  1654.     }
  1655.     result->nMonth = m;
  1656.     result->nDay = (kal_uint8) (day + 1);
  1657.     return KAL_TRUE;
  1658. }
  1659. /*****************************************************************************
  1660.  * FUNCTION
  1661.  *  applib_dt_get_week_number
  1662.  * DESCRIPTION
  1663.  *  Compute the week number of a date
  1664.  * PARAMETERS
  1665.  *  date        [?]     
  1666.  * RETURNS
  1667.  *  void
  1668.  *****************************************************************************/
  1669. U8 mmi_dt_get_week_number(MYTIME *date)
  1670. {
  1671.     /*----------------------------------------------------------------*/
  1672.     /* Local Variables                                                */
  1673.     /*----------------------------------------------------------------*/
  1674.     S32 i, no_of_days, week_num, numdays_inmonth, day_on_firstjan;
  1675.     /*----------------------------------------------------------------*/
  1676.     /* Code Body                                                      */
  1677.     /*----------------------------------------------------------------*/
  1678.     no_of_days = date->nDay;
  1679.     for (i = date->nMonth - 1; i > 0; i--)
  1680.     {
  1681.         /* get the num of days in todays month */
  1682.         numdays_inmonth = LastDayOfMonth((U8) i, date->nYear);
  1683.         no_of_days += numdays_inmonth;
  1684.     }
  1685.     day_on_firstjan = DOW(date->nYear, 1, 1);
  1686.     /* Total no of days/ weekdays */
  1687.     no_of_days += day_on_firstjan;
  1688.     week_num = (no_of_days) / DT_DAYS_OF_WEEK;
  1689.     if ((no_of_days) % DT_DAYS_OF_WEEK > 0)
  1690.     {
  1691.         week_num += 1;
  1692.     }
  1693.     ASSERT(week_num <= CLNDR_MAX_WEEK_NUM);
  1694.     return week_num;
  1695. }
  1696. #endif /* MMI_ON_WIN32 */ 
  1697. /*****************************************************************************
  1698.  * FUNCTION
  1699.  *  CMGetExactTime
  1700.  * DESCRIPTION
  1701.  *  Used by CM to get the Exact Time. Asyncronous Call. Callback is passeds
  1702.  * PARAMETERS
  1703.  *  callback        [IN]        Callback function to be called when get time response comes back
  1704.  * RETURNS
  1705.  *  void
  1706.  *****************************************************************************/
  1707. void CMGetExactTime(DateTimeFuncPtr callback)
  1708. {
  1709. #ifdef __MTK_TARGET__
  1710.     /*----------------------------------------------------------------*/
  1711.     /* Local Variables                                                */
  1712.     /*----------------------------------------------------------------*/
  1713.     /*----------------------------------------------------------------*/
  1714.     /* Code Body                                                      */
  1715.     /*----------------------------------------------------------------*/
  1716.     {
  1717.         /* MYTIME curtime;
  1718.            DTGetRTCTime(&curtime);
  1719.            callback(&curtime); */
  1720.         PRINT_INFORMATION(("<<** CMGetExactTime ** >> CMCallCount = %d, CMCallBackCount = %dn", CMCallCount,
  1721.                            CMCallBackCount));
  1722.         CMDateTimeRequest++;
  1723.         CMDateTimeCallBack[CMCallCount++] = callback;
  1724.         if (CMCallCount == MAX_CM_CALLS)
  1725.         {
  1726.             CMCallCount = 0;
  1727.         }
  1728.         L4GetClockTime(CMGetExactTimeCB);
  1729.     }
  1730. #else /* __MTK_TARGET__ */ 
  1731.     {
  1732.         CMDateTimeRequest++;
  1733.         CMDateTimeCallBack[CMCallCount++] = callback;
  1734.         if (CMCallCount == MAX_CM_CALLS)
  1735.         {
  1736.             CMCallCount = 0;
  1737.         }
  1738.         StartTimer(CM_GET_TIME_CALLBACK, 1000, CMCallBackTimer);
  1739.     }
  1740. #endif /* __MTK_TARGET__ */ 
  1741. }
  1742. /*****************************************************************************
  1743.  * FUNCTION
  1744.  *  CMGetExactTimeCB
  1745.  * DESCRIPTION
  1746.  *  
  1747.  * PARAMETERS
  1748.  *  buf     [?]     [?]
  1749.  * RETURNS
  1750.  *  void
  1751.  *****************************************************************************/
  1752. void CMGetExactTimeCB(void *buf)
  1753. {
  1754. #ifdef __MTK_TARGET__
  1755.     /*----------------------------------------------------------------*/
  1756.     /* Local Variables                                                */
  1757.     /*----------------------------------------------------------------*/
  1758.     mmi_eq_get_rtc_time_rsp_struct *local_data = (mmi_eq_get_rtc_time_rsp_struct*) buf;
  1759.     /* Lisen0522 */
  1760.     extern void update_mainlcd_dt_display(void);
  1761.     extern void update_sublcd_dt_display(void);
  1762.     /*----------------------------------------------------------------*/
  1763.     /* Code Body                                                      */
  1764.     /*----------------------------------------------------------------*/
  1765.     SetDateTime(&(local_data->rtctime[0].data_time));
  1766.     /* gclockData.rtc_wday = local_data->rtctime[0].data_time.rtc_wday;
  1767.        gclockData.rtc_year = local_data->rtctime[0].data_time.rtc_year,
  1768.        gclockData.rtc_mon = local_data->rtctime[0].data_time.rtc_mon,
  1769.        gclockData.rtc_day = local_data->rtctime[0].data_time.rtc_day,
  1770.        gclockData.rtc_hour = local_data->rtctime[0].data_time.rtc_hour,
  1771.        gclockData.rtc_min = local_data->rtctime[0].data_time.rtc_min,
  1772.        gclockData.rtc_sec = local_data->rtctime[0].data_time.rtc_sec; */
  1773.     PRINT_INFORMATION(("<<** CMGetExactTimeCB ** >>n"));
  1774.     if (CMDateTimeRequest > 0)
  1775.     {
  1776.         MYTIME curtime;
  1777.         PRINT_INFORMATION(("<<** CMGetExactTimeCB ** >> CMCallCount = %d, CMCallBackCount = %dn", CMCallCount,
  1778.                            CMCallBackCount));
  1779.         GetDateTime(&curtime);
  1780.         CMDateTimeCallBack[CMCallBackCount++] (&curtime);
  1781.         if (CMCallBackCount == MAX_CM_CALLS)
  1782.         {
  1783.             CMCallBackCount = 0;
  1784.         }
  1785.         CMDateTimeRequest--;
  1786.         return;
  1787.     }
  1788.     /* Lisen0522 */
  1789.     update_mainlcd_dt_display();
  1790.     update_sublcd_dt_display();
  1791. #endif /* __MTK_TARGET__ */ 
  1792. }
  1793. /*****************************************************************************
  1794.  * FUNCTION
  1795.  *  CMCallBackTimer
  1796.  * DESCRIPTION
  1797.  *  Used to simulate CM time function on widows. Calls CM Callback function as set by CM
  1798.  * PARAMETERS
  1799.  *  void
  1800.  * RETURNS
  1801.  *  void
  1802.  *****************************************************************************/
  1803. void CMCallBackTimer(void)
  1804. {
  1805.     /*----------------------------------------------------------------*/
  1806.     /* Local Variables                                                */
  1807.     /*----------------------------------------------------------------*/
  1808.     /*----------------------------------------------------------------*/
  1809.     /* Code Body                                                      */
  1810.     /*----------------------------------------------------------------*/
  1811.     if (CMDateTimeRequest)
  1812.     {
  1813.         MYTIME curtime;
  1814.         GetDateTime(&curtime);
  1815.         CMDateTimeCallBack[CMCallBackCount++] (&curtime);
  1816.         if (CMCallBackCount == MAX_CM_CALLS)
  1817.         {
  1818.             CMCallBackCount = 0;
  1819.         }
  1820.         CMDateTimeRequest--;
  1821.     }
  1822. }
  1823. /*****************************************************************************
  1824.  * FUNCTION
  1825.  *  mmi_dt_get_tz
  1826.  * DESCRIPTION
  1827.  *  Get current time zone of MMI
  1828.  * PARAMETERS
  1829.  *  void
  1830.  * RETURNS
  1831.  *  time zone of current home city.
  1832.  *****************************************************************************/
  1833. FLOAT mmi_dt_get_tz(void)
  1834. {
  1835.     /*----------------------------------------------------------------*/
  1836.     /* Local Variables                                                */
  1837.     /*----------------------------------------------------------------*/
  1838.     /*----------------------------------------------------------------*/
  1839.     /* Code Body                                                      */
  1840.     /*----------------------------------------------------------------*/
  1841.     return GetTimeZone(PhnsetGetHomeCity());
  1842. }
  1843. /*****************************************************************************
  1844.  * FUNCTION
  1845.  *  mmi_dt_set_dst
  1846.  * DESCRIPTION
  1847.  *  
  1848.  * PARAMETERS
  1849.  *  dst     [IN]        
  1850.  * RETURNS
  1851.  *  void
  1852.  *****************************************************************************/
  1853. void mmi_dt_set_dst(U8 dst)
  1854. {
  1855.     /*----------------------------------------------------------------*/
  1856.     /* Local Variables                                                */
  1857.     /*----------------------------------------------------------------*/
  1858.     S16 error;
  1859.     /*----------------------------------------------------------------*/
  1860.     /* Code Body                                                      */
  1861.     /*----------------------------------------------------------------*/
  1862.     WriteValue(NVRAM_SETTING_DT_DST, &dst, DS_BYTE, &error);
  1863.     g_dst = (U8) dst;
  1864. }
  1865. #if 0
  1866. /* under construction !*/
  1867. /* under construction !*/
  1868. /* under construction !*/
  1869. /* under construction !*/
  1870. /* under construction !*/
  1871. #endif /* 0 */ 
  1872. /*****************************************************************************
  1873.  * FUNCTION
  1874.  *  mmi_dt_set_rtc_dt
  1875.  * DESCRIPTION
  1876.  *  This function is to send set time request to L4
  1877.  *  Functionality:
  1878.  * PARAMETERS
  1879.  *  t       [?]     [?]
  1880.  *  a(?)        [IN/OUT](?)
  1881.  *  b(?)        [IN](?)
  1882.  * RETURNS
  1883.  *  void
  1884.  *****************************************************************************/
  1885. void mmi_dt_set_rtc_dt(MYTIME *t)
  1886. {
  1887. #ifdef __MTK_TARGET__
  1888.     /*----------------------------------------------------------------*/
  1889.     /* Local Variables                                                */
  1890.     /*----------------------------------------------------------------*/
  1891.     MYQUEUE msgStruct;
  1892.     RTCTIMEFORMAT *time;
  1893.     /*----------------------------------------------------------------*/
  1894.     /* Code Body                                                      */
  1895.     /*----------------------------------------------------------------*/
  1896.     time = OslConstructDataPtr(sizeof(RTCTIMEFORMAT));
  1897.     time->info.alarm_format = 0;
  1898.     time->info.alarm_index = 0;
  1899.     time->info.type = 0;
  1900.     time->info.text[0] = '';
  1901.     time->info.recurr = 0;
  1902.     time->info.data_time.rtc_sec = 0;
  1903.     time->info.data_time.rtc_min = t->nMin;
  1904.     time->info.data_time.rtc_hour = t->nHour;
  1905.     time->rtc_type = RTC_TIME_CLOCK_IND;
  1906.     time->set_type = RTC_SETTING_TYPE_DATETIME;
  1907.     time->info.data_time.rtc_day = t->nDay;
  1908.     time->info.data_time.rtc_mon = t->nMonth;
  1909.     time->info.data_time.rtc_year = t->nYear - YEARFORMATE;
  1910.     time->info.data_time.rtc_wday = applib_dt_dow(t->nYear, t->nMonth, t->nDay);
  1911.     msgStruct.oslSrcId = MOD_MMI;
  1912.     msgStruct.oslDestId = MOD_L4C;
  1913.     msgStruct.oslMsgId = HW_SET_TIME_REQ;
  1914.     msgStruct.oslSapId = 0;
  1915.     msgStruct.oslDataPtr = (oslParaType*) time;
  1916.     msgStruct.oslPeerBuffPtr = NULL;
  1917.     OslMsgSendExtQueue(&msgStruct);
  1918. #else /* __MTK_TARGET__ */ 
  1919.     MyTime = *t;
  1920. #endif /* __MTK_TARGET__ */ 
  1921. }
  1922. #ifndef MMI_ON_WIN32
  1923. /*****************************************************************************
  1924.  * FUNCTION
  1925.  *  SetDateTime
  1926.  * DESCRIPTION
  1927.  *  Function to set date and time information to global variable of MMI
  1928.  * PARAMETERS
  1929.  *  t       [IN]        Struct variable that stores date and time information from PS
  1930.  * RETURNS
  1931.  *  void
  1932.  *****************************************************************************/
  1933. void SetDateTime(void *t)
  1934. {
  1935.     /*----------------------------------------------------------------*/
  1936.     /* Local Variables                                                */
  1937.     /*----------------------------------------------------------------*/
  1938.     rtc_format_struct *local_data = (rtc_format_struct*) t;
  1939.     /*----------------------------------------------------------------*/
  1940.     /* Code Body                                                      */
  1941.     /*----------------------------------------------------------------*/
  1942. #ifdef __MTK_TARGET__
  1943.     gclockData.rtc_wday = local_data->rtc_wday;
  1944.     gclockData.rtc_year = local_data->rtc_year;
  1945.     gclockData.rtc_mon = local_data->rtc_mon;
  1946.     gclockData.rtc_day = local_data->rtc_day;
  1947.     gclockData.rtc_hour = local_data->rtc_hour;
  1948.     gclockData.rtc_min = local_data->rtc_min;
  1949.     gclockData.rtc_sec = local_data->rtc_sec;
  1950.     if (gclockData.rtc_year > MMI_DT_YEAR_BOUNDARY)
  1951.     {
  1952.         gclockData.rtc_year = 0;    /* reset to 2000 */
  1953.         DTResetTime();
  1954.     }
  1955. #else /* __MTK_TARGET__ */ 
  1956.     MyTime.DayIndex = local_data->rtc_wday;
  1957.     MyTime.nYear = local_data->rtc_year;
  1958.     MyTime.nMonth = local_data->rtc_mon;
  1959.     MyTime.nDay = local_data->rtc_day;
  1960.     MyTime.nHour = local_data->rtc_hour;
  1961.     MyTime.nMin = local_data->rtc_min;
  1962.     MyTime.nSec = local_data->rtc_sec;
  1963. #endif /* __MTK_TARGET__ */ 
  1964. }
  1965. /*****************************************************************************
  1966.  * FUNCTION
  1967.  *  DTResetTimeRsp
  1968.  * DESCRIPTION
  1969.  *  Response handler of reset date/time.
  1970.  * PARAMETERS
  1971.  *  rsp     [?]     [?]
  1972.  * RETURNS
  1973.  *  void
  1974.  *****************************************************************************/
  1975. void DTResetTimeRsp(void *rsp)
  1976. {
  1977. #ifndef MMI_ON_WIN32
  1978.     /*----------------------------------------------------------------*/
  1979.     /* Local Variables                                                */
  1980.     /*----------------------------------------------------------------*/
  1981.     /*----------------------------------------------------------------*/
  1982.     /* Code Body                                                      */
  1983.     /*----------------------------------------------------------------*/
  1984.     AlmReInitialize();
  1985.     SetProtocolEventHandler(L4SetClockRSP, MSG_ID_MMI_EQ_SET_RTC_TIME_RSP);
  1986. #endif /* MMI_ON_WIN32 */ 
  1987. }
  1988. /*****************************************************************************
  1989.  * FUNCTION
  1990.  *  DTResetTime
  1991.  * DESCRIPTION
  1992.  *  Reset Date/Time function when time reaches boundary
  1993.  * PARAMETERS
  1994.  *  void
  1995.  * RETURNS
  1996.  *  void
  1997.  *****************************************************************************/
  1998. static void DTResetTime(void)
  1999. {
  2000. #ifndef MMI_ON_WIN32
  2001.     /*----------------------------------------------------------------*/
  2002.     /* Local Variables                                                */
  2003.     /*----------------------------------------------------------------*/
  2004.     MYQUEUE msgStruct;
  2005.     mmi_eq_set_rtc_time_req_struct *time;
  2006.     /*----------------------------------------------------------------*/
  2007.     /* Code Body                                                      */
  2008.     /*----------------------------------------------------------------*/
  2009.     time = OslConstructDataPtr(sizeof(mmi_eq_set_rtc_time_req_struct));
  2010.     time->info.alarm_format = 0;
  2011.     time->info.alarm_index = 0;
  2012.     time->info.type = 0;
  2013.     time->info.text[0] = '';
  2014.     time->info.recurr = 0;
  2015.     time->rtc_type = RTC_TIME_CLOCK_IND;
  2016.     time->set_type = RTC_SETTING_TYPE_DATETIME;
  2017.     time->info.data_time.rtc_sec = 0;
  2018.     time->info.data_time.rtc_min = gclockData.rtc_min;
  2019.     time->info.data_time.rtc_hour = gclockData.rtc_hour;
  2020.     time->info.data_time.rtc_day = gclockData.rtc_day;
  2021.     time->info.data_time.rtc_mon = gclockData.rtc_mon;
  2022.     time->info.data_time.rtc_wday = gclockData.rtc_wday;
  2023.     time->info.data_time.rtc_year = gclockData.rtc_year;
  2024.     msgStruct.oslSrcId = MOD_MMI;
  2025.     msgStruct.oslDestId = MOD_L4C;
  2026.     msgStruct.oslMsgId = MSG_ID_MMI_EQ_SET_RTC_TIME_REQ;
  2027.     msgStruct.oslSapId = 0;
  2028.     msgStruct.oslDataPtr = (oslParaType*) time;
  2029.     msgStruct.oslPeerBuffPtr = NULL;
  2030.     OslMsgSendExtQueue(&msgStruct);
  2031.     SetProtocolEventHandler(DTResetTimeRsp, MSG_ID_MMI_EQ_SET_RTC_TIME_RSP);
  2032. #endif /* MMI_ON_WIN32 */ 
  2033. }
  2034. /*****************************************************************************
  2035.  * FUNCTION
  2036.  *  DateTimerIndication
  2037.  * DESCRIPTION
  2038.  *  Handler of MSG_ID_MMI_EQ_CLOCK_TICK_IND.
  2039.  *  1. Update global variable in MMI.
  2040.  *  2. Update date/time display in IDLE screen.
  2041.  * PARAMETERS
  2042.  *  p       [?]     [?]
  2043.  *  t(?)        [IN]        Struct variable that stores date and time information from PS(?)
  2044.  * RETURNS
  2045.  *  void
  2046.  *****************************************************************************/
  2047. void DateTimerIndication(void *p)
  2048. {
  2049.     /*----------------------------------------------------------------*/
  2050.     /* Local Variables                                                */
  2051.     /*----------------------------------------------------------------*/
  2052. #ifdef __MTK_TARGET__
  2053.     mmi_eq_clock_tick_ind_struct *local_data = (mmi_eq_clock_tick_ind_struct*) p;
  2054.     /*----------------------------------------------------------------*/
  2055.     /* Code Body                                                      */
  2056.     /*----------------------------------------------------------------*/
  2057.     gclockData.rtc_wday = local_data->rtc_time.rtc_wday;
  2058.     gclockData.rtc_year = local_data->rtc_time.rtc_year;
  2059.     gclockData.rtc_mon = local_data->rtc_time.rtc_mon;
  2060.     gclockData.rtc_day = local_data->rtc_time.rtc_day;
  2061.     gclockData.rtc_hour = local_data->rtc_time.rtc_hour;
  2062.     gclockData.rtc_min = local_data->rtc_time.rtc_min;
  2063.     gclockData.rtc_sec = local_data->rtc_time.rtc_sec;
  2064.     if (gclockData.rtc_year > MMI_DT_YEAR_BOUNDARY)
  2065.     {
  2066.         gclockData.rtc_year = 0;    /* reset to 2000 */
  2067.         DTResetTime();
  2068.     }
  2069. #ifdef __DAILY_WALLPAPER__
  2070.     if ((mmi_bootup_is_searching_or_idle_reached() == MMI_TRUE) && (GetWallpaperRotateStatus() == MMI_TRUE))
  2071.     {
  2072.         if (gWallpaperChangeDate.rtc_year == 0xFF
  2073.             || gWallpaperChangeDate.rtc_mon == 0xFF || gWallpaperChangeDate.rtc_day == 0xFF)
  2074.         {
  2075.             gWallpaperChangeDate.rtc_wday = gclockData.rtc_wday;
  2076.             gWallpaperChangeDate.rtc_year = gclockData.rtc_year;
  2077.             gWallpaperChangeDate.rtc_mon = gclockData.rtc_mon;
  2078.             gWallpaperChangeDate.rtc_day = gclockData.rtc_day;
  2079.             gWallpaperChangeDate.rtc_hour = gclockData.rtc_hour;
  2080.             gWallpaperChangeDate.rtc_min = gclockData.rtc_min;
  2081.             gWallpaperChangeDate.rtc_sec = gclockData.rtc_sec;
  2082.         }
  2083.         else if (gWallpaperChangeDate.rtc_year != gclockData.rtc_year
  2084.                  || gWallpaperChangeDate.rtc_mon != gclockData.rtc_mon
  2085.                  || gWallpaperChangeDate.rtc_day != gclockData.rtc_day)
  2086.         {
  2087.             /* S16 error; */
  2088.             WallPaperDailyChange();
  2089.             gWallpaperChangeDate.rtc_wday = gclockData.rtc_wday;
  2090.             gWallpaperChangeDate.rtc_year = gclockData.rtc_year;
  2091.             gWallpaperChangeDate.rtc_mon = gclockData.rtc_mon;
  2092.             gWallpaperChangeDate.rtc_day = gclockData.rtc_day;
  2093.             gWallpaperChangeDate.rtc_hour = gclockData.rtc_hour;
  2094.             gWallpaperChangeDate.rtc_min = gclockData.rtc_min;
  2095.             gWallpaperChangeDate.rtc_sec = gclockData.rtc_sec;
  2096.             /* WriteRecord(NVRAM_MMI_EF_WALLPAPER_MODTIME_LID,1,(void *)&gWallpaperChangeDate, sizeof(gWallpaperChangeDate), &error); */
  2097.         }
  2098.     }
  2099. #endif /* __DAILY_WALLPAPER__ */ 
  2100. #ifdef __MMI_LCD_PARTIAL_ON__
  2101.     if ((mmi_bootup_is_searching_or_idle_reached() == MMI_TRUE) || mmi_bootup_is_sim_removed() == MMI_TRUE)
  2102.     {
  2103.         RedrawPartialOnScreenSaverIfOk();
  2104.     }
  2105. #endif /* __MMI_LCD_PARTIAL_ON__ */ 
  2106.     /* Lisen0522 */
  2107. #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
  2108.     if (gIsInSleepMode == KAL_FALSE)
  2109.     {
  2110.         update_mainlcd_dt_display();
  2111.     }
  2112. #else /* !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) */ 
  2113.     update_mainlcd_dt_display();
  2114. #endif /* !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) */ 
  2115.     update_sublcd_dt_display();
  2116. #else /* __MTK_TARGET__ */ 
  2117.     DateTimerProc();
  2118. #endif /* __MTK_TARGET__ */ 
  2119. }
  2120. /*****************************************************************************
  2121.  * FUNCTION
  2122.  *  mmi_dt_check_rtc_time
  2123.  * DESCRIPTION
  2124.  * Check if rtc time is valid
  2125.  * PARAMETERS
  2126.  *  p       [?]     [?]
  2127.  *  t(?)        [IN]        Struct variable that stores date and time information from PS(?)
  2128.  * RETURNS
  2129.  *  void
  2130.  *****************************************************************************/
  2131. void mmi_dt_check_rtc_time(void)
  2132. {
  2133.     if (gclockData.rtc_year > MMI_DT_YEAR_BOUNDARY)
  2134.     {
  2135.         gclockData.rtc_year = 0;    /* reset to 2000 */
  2136.         DTResetTime();
  2137.     }
  2138. }
  2139. #endif /* MMI_ON_WIN32 */ 
  2140. #endif /* _MMI_DATETIME_C */ // #ifndef _MMI_DATETIME_C