time.c revision 199767f8919635c4928607450d9e0abb932109ce
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1999, 2000
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Intel Corporation.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 3. All advertising materials mentioning features or use of this software
199767f8919635c4928607450d9e0abb932109ceToomas Soome * must display the following acknowledgement:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This product includes software developed by Intel Corporation and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * its contributors.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 4. Neither the name of Intel Corporation or its contributors may be
199767f8919635c4928607450d9e0abb932109ceToomas Soome * used to endorse or promote products derived from this software
199767f8919635c4928607450d9e0abb932109ceToomas Soome * without specific prior written permission.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
199767f8919635c4928607450d9e0abb932109ceToomas Soome * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
199767f8919635c4928607450d9e0abb932109ceToomas Soome * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
199767f8919635c4928607450d9e0abb932109ceToomas Soome * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THE POSSIBILITY OF SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// Accurate only for the past couple of centuries;
199767f8919635c4928607450d9e0abb932109ceToomas Soome// that will probably do.
199767f8919635c4928607450d9e0abb932109ceToomas Soome// (#defines From FreeBSD 3.2 lib/libc/stdtime/tzfile.h)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
199767f8919635c4928607450d9e0abb932109ceToomas Soome // These arrays give the cumulative number of days up to the first of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome // month number used as the index (1 -> 12) for regular and leap years.
199767f8919635c4928607450d9e0abb932109ceToomas Soome // The value at index 13 is for the whole year.
199767f8919635c4928607450d9e0abb932109ceToomas Soome 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 },
199767f8919635c4928607450d9e0abb932109ceToomas Soome 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 }};
199767f8919635c4928607450d9e0abb932109ceToomas Soome // Do a santity check
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ( ETime->Year < 1998 || ETime->Year > 2099 ||
199767f8919635c4928607450d9e0abb932109ceToomas Soome (ETime->TimeZone > 1440 && ETime->TimeZone != 2047) ) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (Year = 1970; Year != ETime->Year; ++Year) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome UTime += (CumulativeDays[isleap(Year)][13] * SECSPERDAY);
199767f8919635c4928607450d9e0abb932109ceToomas Soome // UTime should now be set to 00:00:00 on Jan 1 of the file's year.
199767f8919635c4928607450d9e0abb932109ceToomas Soome UTime += (CumulativeDays[isleap(ETime->Year)][ETime->Month] * SECSPERDAY);
199767f8919635c4928607450d9e0abb932109ceToomas Soome // UTime should now be set to 00:00:00 on the first of the file's month and year
199767f8919635c4928607450d9e0abb932109ceToomas Soome // Days -- Don't count the file's day
199767f8919635c4928607450d9e0abb932109ceToomas Soome UTime += (((ETime->Day > 0) ? ETime->Day-1:0) * SECSPERDAY);
199767f8919635c4928607450d9e0abb932109ceToomas Soome // EFI time is repored in local time. Adjust for any time zone offset to
199767f8919635c4928607450d9e0abb932109ceToomas Soome // get true UT
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ( ETime->TimeZone != EFI_UNSPECIFIED_TIMEZONE ) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome // TimeZone is kept in minues...
199767f8919635c4928607450d9e0abb932109ceToomas Soome // Get time from EFI
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome // Convert to UNIX time (ie seconds since the epoch
199767f8919635c4928607450d9e0abb932109ceToomas Soome tp->tv_usec = 0; /* EfiTime.Nanosecond * 1000; */
199767f8919635c4928607450d9e0abb932109ceToomas Soome // Do something with the timezone if needed
199767f8919635c4928607450d9e0abb932109ceToomas Soome EfiTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE ? 0 : EfiTime.TimeZone;
199767f8919635c4928607450d9e0abb932109ceToomas Soome // This isn't quit right since it doesn't deal with EFI_TIME_IN_DAYLIGHT