ReactOS  0.4.15-dev-3324-gda4e15f
time.c File Reference
#include "precomp.h"
Include dependency graph for time.c:

Go to the source code of this file.

Macros

#define LEAPS_THRU_END_OF(y)   ((y)/4 - (y)/100 + (y)/400)
 

Functions

BOOLEAN NTAPI LlbIsLeapYear (IN ULONG Year)
 
ULONG NTAPI LlbDayOfMonth (IN ULONG Month, IN ULONG Year)
 
VOID NTAPI LlbConvertRtcTime (IN ULONG RtcTime, OUT TIMEINFO *TimeInfo)
 
TIMEINFO *NTAPI LlbGetTime (VOID)
 

Variables

UCHAR LlbDaysInMonth [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
 
TIMEINFO LlbTime
 

Macro Definition Documentation

◆ LEAPS_THRU_END_OF

#define LEAPS_THRU_END_OF (   y)    ((y)/4 - (y)/100 + (y)/400)

Definition at line 11 of file time.c.

Function Documentation

◆ LlbConvertRtcTime()

VOID NTAPI LlbConvertRtcTime ( IN ULONG  RtcTime,
OUT TIMEINFO TimeInfo 
)

Definition at line 40 of file time.c.

42 {
43  ULONG Month, Year, Days, DaysLeft;
44 
45  /* Count the days, keep the minutes */
46  Days = RtcTime / 86400;
47  RtcTime -= Days * 86400;
48 
49  /* Get the year, based on days since 1970 */
50  Year = 1970 + Days / 365;
51 
52  /* Account for leap years which changed the number of days/year */
53  Days -= (Year - 1970) * 365 + LEAPS_THRU_END_OF(Year - 1) - LEAPS_THRU_END_OF(1970 - 1);
54  if (Days < 0)
55  {
56  /* We hit a leap year, so fixup the math */
57  Year--;
58  Days += 365 + LlbIsLeapYear(Year);
59  }
60 
61  /* Count months */
62  for (Month = 0; Month < 11; Month++)
63  {
64  /* How many days in this month? */
65  DaysLeft = Days - LlbDayOfMonth(Month, Year);
66  if (DaysLeft < 0) break;
67 
68  /* How many days left total? */
69  Days = DaysLeft;
70  }
71 
72  /* Write the structure */
73  TimeInfo->Year = Year;
74  TimeInfo->Day = Days + 1;
75  TimeInfo->Month = Month + 1;
76  TimeInfo->Hour = RtcTime / 3600;
77  RtcTime -= TimeInfo->Hour * 3600;
78  TimeInfo->Minute = RtcTime / 60;
79  TimeInfo->Second = RtcTime - TimeInfo->Minute * 60;
80 }
BOOLEAN NTAPI LlbIsLeapYear(IN ULONG Year)
Definition: time.c:23
#define LEAPS_THRU_END_OF(y)
Definition: time.c:11
ULONG NTAPI LlbDayOfMonth(IN ULONG Month, IN ULONG Year)
Definition: time.c:31
unsigned int ULONG
Definition: retypes.h:1

Referenced by LlbGetTime().

◆ LlbDayOfMonth()

ULONG NTAPI LlbDayOfMonth ( IN ULONG  Month,
IN ULONG  Year 
)

Definition at line 31 of file time.c.

33 {
34  /* Check how many days a month has, accounting for leap yearS */
35  return LlbDaysInMonth[Month] + (LlbIsLeapYear(Year) && Month == 1);
36 }
BOOLEAN NTAPI LlbIsLeapYear(IN ULONG Year)
Definition: time.c:23
UCHAR LlbDaysInMonth[]
Definition: time.c:13

Referenced by LlbConvertRtcTime().

◆ LlbGetTime()

TIMEINFO* NTAPI LlbGetTime ( VOID  )

Definition at line 84 of file time.c.

85 {
86  ULONG RtcTime;
87 
88  /* Read RTC time */
89  RtcTime = LlbHwRtcRead();
90 #ifndef _ZOOM2_
91  /* Convert it */
92  LlbConvertRtcTime(RtcTime, &LlbTime);
93 #endif
94  return &LlbTime;
95 }
VOID NTAPI LlbConvertRtcTime(IN ULONG RtcTime, OUT TIMEINFO *TimeInfo)
Definition: time.c:40
unsigned int ULONG
Definition: retypes.h:1
ULONG LlbHwRtcRead(VOID)
Definition: hwinfo.c:132
TIMEINFO LlbTime
Definition: time.c:16

Referenced by LlbFwGetTime().

◆ LlbIsLeapYear()

BOOLEAN NTAPI LlbIsLeapYear ( IN ULONG  Year)

Definition at line 23 of file time.c.

24 {
25  /* Every 4, 100, or 400 years */
26  return (!(Year % 4) && (Year % 100)) || !(Year % 400);
27 }

Referenced by LlbConvertRtcTime(), and LlbDayOfMonth().

Variable Documentation

◆ LlbDaysInMonth

UCHAR LlbDaysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}

Definition at line 13 of file time.c.

Referenced by LlbDayOfMonth().

◆ LlbTime

TIMEINFO LlbTime

Definition at line 16 of file time.c.

Referenced by LlbGetTime().