XilinxProcessorIPLib/drivers/rtcpsu/src/xrtcpsu.c
void XRtcPsu_SecToDateTime(u32 Seconds, XRtcPsu_DT *dt)
{
	u32 CurrentTime;
	u32 TempDays;
	u32 DaysPerMonth;
	u32 Leap = 0U;

	CurrentTime = Seconds;
	dt->Sec = CurrentTime % 60U;
	CurrentTime /= 60U;
	dt->Min = CurrentTime % 60U;
	CurrentTime /= 60U;
	dt->Hour = CurrentTime % 24U;
	TempDays = CurrentTime / 24U;

	if (TempDays == 0U)
        {
		TempDays = 1U;
        }
	dt->WeekDay = TempDays % 7U;

	for (dt->Year = 0U; dt->Year <= 99U; ++(dt->Year)) {
		if ((dt->Year % 4U) == 0U)
                {
			Leap = 1U;
                }
		else
                {
			Leap = 0U;
                }

		if (TempDays <= (365U + Leap))
                {
			break;
                }

		TempDays -= (365U + Leap);
	}

	for (dt->Month = 1U; dt->Month >= 1U; ++(dt->Month)) {
		DaysPerMonth = DaysInMonth[dt->Month - (u32)1];
		if ((Leap == 1U) && (dt->Month == 2U))
                {
			DaysPerMonth++;
                }
		if (TempDays <= DaysPerMonth)
                {
			break;
                }

		TempDays -= DaysPerMonth;
	}

	dt->Day = TempDays;
	dt->Year += 2000U;
}
/****************************************************************************/
/**
 *
 *	This function translates time in seconds to a YEAR:MON:DAY HR:MIN:SEC
 *	format and saves it in the DT structure variable.
 *	It also reports the weekday.
 *
 * @param	Seconds is the time value that has to be shown in DateTime
 *		format.
 * @param	dt is the DateTime format variable that stores the translated
 *		time.
 *
 * @return	None.
 *
 * @note	This API supports this century i.e., 2000 - 2099 years only.
 *
 *****************************************************************************/
This function translates time in seconds to a YEAR:MON:DAY HR:MIN:SEC
format and saves it in the DT structure variable.
It also reports the weekday.

@param       Seconds is the time value that has to be shown in DateTime
format.
@param       dt is the DateTime format variable that stores the translated
time.

@return      None.

@note        This API supports this century i.e., 2000 - 2099 years only.
This function translates time in seconds to a YEAR : MON : DAY HR : MIN : SEC format and saves it in the DT structure variable . It also reports the weekday . @param Seconds is the time value that has to be shown in DateTime format . @param dt is the DateTime format variable that stores the translated time . @return None . @note This API supports this century i . e . 2000 - 2099 years only .
void XRtcPsu_SecToDateTime(u32 Seconds, XRtcPsu_DT *dt)
{
	u32 CurrentTime;
	u32 TempDays;
	u32 DaysPerMonth;
	u32 Leap = 0U;
	CurrentTime = Seconds;
	dt->Sec = CurrentTime % 60U;
	CurrentTime /= 60U;
	dt->Min = CurrentTime % 60U;
	CurrentTime /= 60U;
	dt->Hour = CurrentTime % 24U;
	TempDays = CurrentTime / 24U;
	if (TempDays == 0U)
        {
		TempDays = 1U;
        }
	dt->WeekDay = TempDays % 7U;
	for (dt->Year = 0U; dt->Year <= 99U; ++(dt->Year)) {
		if ((dt->Year % 4U) == 0U)
                {
			Leap = 1U;
                }
		else
                {
			Leap = 0U;
                }
		if (TempDays <= (365U + Leap))
                {
			break;
                }
		TempDays -= (365U + Leap);
	}
	for (dt->Month = 1U; dt->Month >= 1U; ++(dt->Month)) {
		DaysPerMonth = DaysInMonth[dt->Month - (u32)1];
		if ((Leap == 1U) && (dt->Month == 2U))
                {
			DaysPerMonth++;
                }
		if (TempDays <= DaysPerMonth)
                {
			break;
                }
		TempDays -= DaysPerMonth;
	}
	dt->Day = TempDays;
	dt->Year += 2000U;
}
void XRtcPsu_SecToDateTime ( u32 Seconds , XRtcPsu_DT * dt ) { u32 CurrentTime ; u32 TempDays ; u32 DaysPerMonth ; u32 Leap = 0U ; CurrentTime = Seconds ; dt -> Sec = CurrentTime % 60U ; CurrentTime /= 60U ; dt -> Min = CurrentTime % 60U ; CurrentTime /= 60U ; dt -> Hour = CurrentTime % 24U ; TempDays = CurrentTime / 24U ; if ( TempDays == 0U ) { TempDays = 1U ; } dt -> WeekDay = TempDays % 7U ; for ( dt -> Year = 0U ; dt -> Year <= 99U ; ++ ( dt -> Year ) ) { if ( ( dt -> Year % 4U ) == 0U ) { Leap = 1U ; } else { Leap = 0U ; } if ( TempDays <= ( 365U + Leap ) ) { break ; } TempDays -= ( 365U + Leap ) ; } for ( dt -> Month = 1U ; dt -> Month >= 1U ; ++ ( dt -> Month ) ) { DaysPerMonth = DaysInMonth [ dt -> Month - ( u32 ) 1 ] ; if ( ( Leap == 1U ) && ( dt -> Month == 2U ) ) { DaysPerMonth ++ ; } if ( TempDays <= DaysPerMonth ) { break ; } TempDays -= DaysPerMonth ; } dt -> Day = TempDays ; dt -> Year += 2000U ; }
This function translates time in seconds to a YEAR:MON:DAY HR:MIN:SEC
      format and saves it in the DT structure variable.
This function translates time in seconds to a YEAR : MON : DAY HR : MIN : SEC format and saves it in the DT structure variable .