2 * Copyright (c) 1999, 2000
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
20 * This product includes software developed by Intel Corporation and
23 * 4. Neither the name of Intel Corporation or its contributors may be
24 * used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
37 * THE POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
51 // Accurate only for the past couple of centuries;
52 // that will probably do.
54 // (#defines From FreeBSD 3.2 lib/libc/stdtime/tzfile.h)
57 #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
58 #define SECSPERHOUR ( 60*60 )
59 #define SECSPERDAY (24 * SECSPERHOUR)
72 efi_time(EFI_TIME *ETime)
75 // These arrays give the cumulative number of days up to the first of the
76 // month number used as the index (1 -> 12) for regular and leap years.
77 // The value at index 13 is for the whole year.
79 static time_t CumulativeDays[2][14] = {
86 31 + 28 + 31 + 30 + 31,
87 31 + 28 + 31 + 30 + 31 + 30,
88 31 + 28 + 31 + 30 + 31 + 30 + 31,
89 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,
90 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
91 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
92 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,
93 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 },
100 31 + 29 + 31 + 30 + 31,
101 31 + 29 + 31 + 30 + 31 + 30,
102 31 + 29 + 31 + 30 + 31 + 30 + 31,
103 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31,
104 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
105 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
106 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,
107 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 }};
113 // Do a santity check
115 if ( ETime->Year < 1998 || ETime->Year > 2099 ||
116 ETime->Month == 0 || ETime->Month > 12 ||
117 ETime->Day == 0 || ETime->Month > 31 ||
119 ETime->Minute > 59 ||
120 ETime->Second > 59 ||
121 ETime->TimeZone < -1440 ||
122 (ETime->TimeZone > 1440 && ETime->TimeZone != 2047) ) {
130 for (Year = 1970; Year != ETime->Year; ++Year) {
131 UTime += (CumulativeDays[isleap(Year)][13] * SECSPERDAY);
135 // UTime should now be set to 00:00:00 on Jan 1 of the file's year.
139 UTime += (CumulativeDays[isleap(ETime->Year)][ETime->Month] * SECSPERDAY);
142 // UTime should now be set to 00:00:00 on the first of the file's month and year
144 // Days -- Don't count the file's day
146 UTime += (((ETime->Day > 0) ? ETime->Day-1:0) * SECSPERDAY);
151 UTime += (ETime->Hour * SECSPERHOUR);
156 UTime += (ETime->Minute * 60);
161 UTime += ETime->Second;
164 // EFI time is repored in local time. Adjust for any time zone offset to
167 if ( ETime->TimeZone != EFI_UNSPECIFIED_TIMEZONE ) {
169 // TimeZone is kept in minues...
171 UTime += (ETime->TimeZone * 60);
179 OUT struct timeval *tp,
180 OUT struct timezone *tzp
184 EFI_TIME_CAPABILITIES Capabilities;
191 Status = RS->GetTime(&EfiTime, &Capabilities);
192 if (EFI_ERROR(Status))
196 // Convert to UNIX time (ie seconds since the epoch
199 tp->tv_sec = efi_time( &EfiTime );
200 tp->tv_usec = 0; /* EfiTime.Nanosecond * 1000; */
203 // Do something with the timezone if needed
207 tzp->tz_minuteswest =
208 EfiTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE ? 0 : EfiTime.TimeZone;
210 // This isn't quit right since it doesn't deal with EFI_TIME_IN_DAYLIGHT
213 EfiTime.Daylight & EFI_TIME_ADJUST_DAYLIGHT ? 1 : 0;
223 EFI_GetTimeOfDay(&tv, 0);