ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

time.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS Boot Loader
00003  * LICENSE:         BSD - See COPYING.ARM in the top level directory
00004  * FILE:            boot/armllb/hw/time.c
00005  * PURPOSE:         LLB Time Routines
00006  * PROGRAMMERS:     ReactOS Portable Systems Group
00007  */
00008 
00009 #include "precomp.h"
00010 
00011 #define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400)
00012 
00013 UCHAR LlbDaysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
00014 
00015 #ifndef _ZOOM2_
00016 TIMEINFO LlbTime;
00017 #else
00018 extern TIMEINFO LlbTime;
00019 #endif
00020 
00021 BOOLEAN
00022 NTAPI
00023 LlbIsLeapYear(IN ULONG Year)
00024 {
00025     /* Every 4, 100, or 400 years */
00026     return (!(Year % 4) && (Year % 100)) || !(Year % 400);
00027 }
00028 
00029 ULONG
00030 NTAPI
00031 LlbDayOfMonth(IN ULONG Month,
00032               IN ULONG Year)
00033 {
00034     /* Check how many days a month has, accounting for leap yearS */
00035     return LlbDaysInMonth[Month] + (LlbIsLeapYear(Year) && Month == 1);
00036 }
00037 
00038 VOID
00039 NTAPI
00040 LlbConvertRtcTime(IN ULONG RtcTime,
00041                   OUT TIMEINFO* TimeInfo)
00042 {
00043     ULONG Month, Year, Days, DaysLeft;
00044 
00045     /* Count the days, keep the minutes */
00046     Days = RtcTime / 86400;
00047     RtcTime -= Days * 86400;
00048 
00049     /* Get the year, based on days since 1970 */
00050     Year = 1970 + Days / 365;
00051     
00052     /* Account for leap years which changed the number of days/year */
00053     Days -= (Year - 1970) * 365 + LEAPS_THRU_END_OF(Year - 1) - LEAPS_THRU_END_OF(1970 - 1);
00054     if (Days < 0)
00055     {
00056         /* We hit a leap year, so fixup the math */
00057         Year--;
00058         Days += 365 + LlbIsLeapYear(Year);
00059     }
00060 
00061     /* Count months */
00062     for (Month = 0; Month < 11; Month++)
00063     {
00064         /* How many days in this month? */
00065         DaysLeft = Days - LlbDayOfMonth(Month, Year);
00066         if (DaysLeft < 0) break;
00067         
00068         /* How many days left total? */             
00069         Days = DaysLeft;
00070     }
00071 
00072     /* Write the structure */
00073     TimeInfo->Year = Year;
00074     TimeInfo->Day = Days + 1;
00075     TimeInfo->Month = Month + 1;
00076     TimeInfo->Hour = RtcTime / 3600;
00077     RtcTime -= TimeInfo->Hour * 3600;
00078     TimeInfo->Minute = RtcTime / 60;
00079     TimeInfo->Second = RtcTime - TimeInfo->Minute * 60;
00080 }
00081 
00082 TIMEINFO*
00083 NTAPI
00084 LlbGetTime(VOID)
00085 {
00086     ULONG RtcTime;
00087 
00088     /* Read RTC time */
00089     RtcTime = LlbHwRtcRead();
00090 #ifndef _ZOOM2_
00091     /* Convert it */
00092     LlbConvertRtcTime(RtcTime, &LlbTime);
00093 #endif
00094     return &LlbTime;
00095 }
00096 
00097 /* EOF */

Generated on Mon May 28 2012 04:18:04 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.