📄 app_datetime.c
字号:
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* app_datetime.c
*
* Project:
* --------
* MAUI
*
* Description:
* ------------
* This file implements common interfaces for date/time.
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include "kal_release.h"
#include "rtc_sw.h"
#include "app_datetime.h"
#include "custom_mmi_default_value.h"
/*****************************************************************************
* Define
*****************************************************************************/
#define DT_UTC_BASE_YEAR 1970
#define DT_MONTH_PER_YEAR 12
#define DT_DAY_PER_YEAR 365
#define DT_SEC_PER_DAY 86400
#define DT_SEC_PER_HOUR 3600
#define DT_SEC_PER_MIN 60
#define DT_MIN_PER_HR 60
#define DT_HRS_PRE_DAY 24
#define DT_MAX_YEAR 2030
#define DT_MIN_YEAR 2000
#define YEARFORMATE 2000
/*****************************************************************************
* Typedef
*****************************************************************************/
/*****************************************************************************
* Local Variable
*****************************************************************************/
static kal_char *weekday_c[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; /* Compact String */
static kal_char *weekday_f[] = { "Sunday", "Monday", "Tuesday", "Wedensday", "Thursday", "Friday", "Saturday" }; /* Full string */
static kal_char *months_c[] = { "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov" }; /* Compact string */
static kal_char *months_f[] = { "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" }; /* Full string */
static const kal_int16 accumulating_monthdays[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
/*****************************************************************************
* Local Function
*****************************************************************************/
/*****************************************************************************
* Global Variable
*****************************************************************************/
const kal_uint8 g_dt_day_per_mon[DT_MONTH_PER_YEAR] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
/*****************************************************************************
* Global Function
*****************************************************************************/
/* MMI functions */
extern float GetTimeZone(kal_uint8 cityIndex);
extern kal_uint8 PhnsetGetHomeCity(void);
extern kal_uint8 mmi_dt_is_dst(void);
extern void DTGetRTCTime(MYTIME *t);
/*****************************************************************************
* FUNCTION
* applib_dt_is_leap_year
* DESCRIPTION
* Function to find out if given year is a leap year
* PARAMETERS
* year [IN]
* y(?) [IN] Year of the date to be computed (example, 2004)
* RETURNS
* 1 if the year is leap; otherwise 0.
*****************************************************************************/
kal_uint8 applib_dt_is_leap_year(kal_uint16 year)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if ((year % 400) == 0)
{
return 1;
}
else if ((year % 100) == 0)
{
return 0;
}
else if ((year % 4) == 0)
{
return 1;
}
else
{
return 0;
}
}
/*****************************************************************************
* FUNCTION
* applib_dt_last_day_of_mon
* DESCRIPTION
* Function to find the last day of specific month.
* PARAMETERS
* month [IN] Month
* year [IN] Year
* RETURNS
* number of days
*****************************************************************************/
kal_uint8 applib_dt_last_day_of_mon(kal_uint8 month, kal_uint16 year)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (month != 2)
{
return g_dt_day_per_mon[month - 1];
}
else
{
return g_dt_day_per_mon[1] + applib_dt_is_leap_year(year);
}
}
/*****************************************************************************
* FUNCTION
* applib_dt_dow
* DESCRIPTION
* Function to compute current day of week.
* PARAMETERS
* y [IN] Year of the date to be computed. (example, 2004)
* m [IN] Month of the date to be computed
* d [IN] Day of the date to be computed
* RETURNS
* kal_uint8 index of day of week
*****************************************************************************/
kal_uint8 applib_dt_dow(kal_uint16 y, kal_uint8 m, kal_uint8 d)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (m < 3)
{
m += 13;
y--;
}
else
{
m++;
}
return (d + 26 * m / 10 + y + y / 4 - y / 100 + y / 400 + 6) % 7;
}
/*****************************************************************************
* FUNCTION
* applib_dt_utc_to_rtc
* DESCRIPTION
* compute utc time to rtc time
* PARAMETERS
* tz [IN] Time zone
* utc [IN] Utc time
* RETURNS
* result of time
*****************************************************************************/
applib_time_struct applib_dt_utc_to_rtc(float tz, applib_time_struct *utc)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
applib_time_struct result;
applib_time_struct incTime;
kal_bool negative = KAL_FALSE;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (tz < 0)
{
negative = KAL_TRUE;
tz = 0 - tz;
}
incTime = applib_conv_tz_to_mytime(tz);
if (negative)
{
applib_dt_decrease_time(utc, &incTime, &result);
}
else
{
applib_dt_increase_time(utc, &incTime, &result);
}
return result;
}
/*****************************************************************************
* FUNCTION
* applib_conv_tz_to_mytime
* DESCRIPTION
* contert timezone to MYTIME structure
* PARAMETERS
* tz [IN] Time zone to be converted
* RETURNS
* result in MYTIME structure
*****************************************************************************/
applib_time_struct applib_conv_tz_to_mytime(float tz)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
applib_time_struct result;
kal_int16 timezone = (kal_int16) (tz * 4);
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
kal_mem_set(&result, 0, sizeof(applib_time_struct));
result.nHour = (kal_uint8) (timezone / 4);
result.nMin = (kal_uint8) ((timezone % 4) * 15);
return result;
}
/*****************************************************************************
* FUNCTION
* applib_dt_decrease_time
* DESCRIPTION
* Decrease a reference time by some time
* PARAMETERS
* timeToDecrement [IN] Time to be decreased
* decrement [IN] Time to decrease
* Result [IN/OUT] Result of compuatation
* RETURNS
* void
*****************************************************************************/
void applib_dt_decrease_time(
applib_time_struct *timeToDecrement,
applib_time_struct *decrement,
applib_time_struct *Result)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (decrement->nSec != 0)
{
if (timeToDecrement->nSec >= decrement->nSec)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -