Exemple #1
0
/*************************************************************************
 * Function Name: RTC_SetDateTime
 * Parameters: LPC_Rtc_DateTime_t *pDateTime
 * Return: int
 *             	0: sucess
 *		1: fail
 * Description: Set your specifying date and time
 *
 *************************************************************************/
int RTC_SetDateTime (LPC_Rtc_DateTime_t *pDateTime)
{
    /* Valid Judge */
    if (IsValidDay(pDateTime->year, pDateTime->month, pDateTime->day) == 0){
        return 1;
    }
    if ( pDateTime->hour > 23 || pDateTime->minute > 59 ||pDateTime->second > 59){
        return 1;
    }
    /* Calulate DOW, DOY */
    pDateTime->doy = GetDOY(pDateTime->year, pDateTime->month, pDateTime->day);
    pDateTime->dow = GetDOW(pDateTime->year, pDateTime->month, pDateTime->day);

    RTC_DOM     = pDateTime->day;
    RTC_MONTH   = pDateTime->month;
    RTC_YEAR    = pDateTime->year;
    RTC_DOW     = pDateTime->dow;
    RTC_DOY     = pDateTime->doy;
    RTC_HOUR    = pDateTime->hour;
    RTC_MIN     = pDateTime->minute;
    RTC_SEC     = pDateTime->second;

    RTC_datetime_to_unix( &unix_time, pDateTime);

    return 0;
}
Exemple #2
0
int GetDaysFrom1984To(int day, int month, int year) {
	int y;
	int32 days=0;
	
	if (year<1984) return -1;
	
	for (y=1984; y<year;y++) {
		days+=GetDaysInYear(y);
	}
	days+=GetDOY(day, month, year);
	
	return days;
}
Exemple #3
0
/*************************************************************************
 * Function Name: GetDOW
 * Parameters:  unsigned short Year
 *		unsigned char month
 *		unsigned char day
 *
 * Return: int -- (0~6)
 *
 * Description: Get the day of week according to the date.
 *
 * NOTE: Year is not smaller than RTC_YEARMIN (1901).
 *
 *************************************************************************/
static int GetDOW (unsigned short year, unsigned char month, char day)
{
    int i, dow=0;

    for (i = RTC_BASEYEAR, dow = 0; i < year; i++)
    {
        dow +=365;
        if  (IsLeapYear(i)){
            dow++;
        }
    }

    dow +=  GetDOY (year, month, day) - 1;
    dow = (dow + RTC_BASEDOW) % 7;

    return dow;
}
Exemple #4
0
/*************************************************************************
 * Function Name: RTC_SetDate
 * Parameters: LPC_Rtc_Date_t *pDate
 * Return: int
 *             	0: sucess
 *		1: fail
 * Description: Set your specifying date
 *
 *************************************************************************/
int RTC_SetDate (LPC_Rtc_Date_t *pDate)
{
    /* Valid Judge */
    if (IsValidDay(pDate->year, pDate->month, pDate->day) == 0)
        return 1;

    /* Calulate DOW, DOY */
    pDate->doy = GetDOY(pDate->year, pDate->month, pDate->day);
    pDate->dow = GetDOW(pDate->year, pDate->month, pDate->day);

    RTC_DOM=pDate->day;
    RTC_MONTH=pDate->month;
    RTC_YEAR=pDate->year;
    RTC_DOW=pDate->dow;
    RTC_DOY=pDate->doy;

    return 0;
}