summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstoddard <stoddard@13f79535-47bb-0310-9956-ffa450edef68>2001-02-02 14:43:53 +0000
committerstoddard <stoddard@13f79535-47bb-0310-9956-ffa450edef68>2001-02-02 14:43:53 +0000
commit6c2b09cc343628c6aa255aa6a2a31a5890f1db63 (patch)
treea86fe7c8982364502745719651fd841ef5dc139a
parent6a31ef1f764c2f1e9369987eaa6523214a9ffc0e (diff)
downloadlibapr-6c2b09cc343628c6aa255aa6a2a31a5890f1db63.tar.gz
Win32: (IsLeapYear): New macro for quickly figgerin' out if a given year is a
leap year. (SystemTimeToAprExpTime): Perform the calculation of tm_yday. Also, negate the sign of the tm_gmtoff field to be consistent with Unix platforms and APR header file comments. ToDo: Perhaps the IsLeapYear macro is useful for other OSes. Submitted by: Mike Pilato Reviewed by: Bill Stoddard git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@61181 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--CHANGES6
-rw-r--r--time/win32/time.c20
2 files changed, 23 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index c72044977..3e4353839 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,10 @@
Changes with APR b1
+ *) Some fixes in the Win32 time support.
+ (IsLeapYear): New macro for quickly figgerin' out if a given year is a
+ leap year. (SystemTimeToAprExpTime): Perform the calculation of
+ tm_yday. Also, negate the sign of the tm_gmtoff field to be
+ consistent with Unix platforms and APR header file comments.
+ [Mike Pilato]
*) Implement WinNT Unix'ish permissions. [William Rowe]
diff --git a/time/win32/time.c b/time/win32/time.c
index 894a5db3c..6d46f69f6 100644
--- a/time/win32/time.c
+++ b/time/win32/time.c
@@ -77,6 +77,7 @@ void FileTimeToAprTime(apr_time_t *result, FILETIME *input)
*result -= APR_DELTA_EPOCH_IN_USEC; /* Convert from Windows epoch to Unix epoch */
return;
}
+
void AprTimeToFileTime(LPFILETIME pft, apr_time_t t)
{
LONGLONG ll;
@@ -87,10 +88,17 @@ void AprTimeToFileTime(LPFILETIME pft, apr_time_t t)
return;
}
+/* Leap year is any year divisible by four, but not by 100 unless also
+ * divisible by 400
+ */
+#define IsLeapYear(y) ((!(y % 4)) ? (((!(y % 400)) && (y % 100)) ? 1 : 0) : 0)
+
void SystemTimeToAprExpTime(apr_exploded_time_t *xt, SYSTEMTIME *tm)
{
TIME_ZONE_INFORMATION tz;
DWORD rc;
+ static const int dayoffset[12] =
+ {0, 31, 59, 90, 120, 151, 182, 212, 243, 273, 304, 334};
xt->tm_usec = tm->wMilliseconds * 1000;
xt->tm_sec = tm->wSecond;
@@ -100,7 +108,13 @@ void SystemTimeToAprExpTime(apr_exploded_time_t *xt, SYSTEMTIME *tm)
xt->tm_mon = tm->wMonth - 1;
xt->tm_year = tm->wYear - 1900;
xt->tm_wday = tm->wDayOfWeek;
- xt->tm_yday = 0; /* ToDo: need to compute this */
+ xt->tm_yday = dayoffset[xt->tm_mon] + (tm->wDay - 1);
+
+ /* If this is a leap year, and we're past the 28th of Feb. (the
+ * 58th day after Jan. 1), we'll increment our tm_yday by one.
+ */
+ if (IsLeapYear(tm->wYear) && (xt->tm_yday > 58))
+ xt->tm_yday++;
rc = GetTimeZoneInformation(&tz);
switch (rc) {
@@ -110,11 +124,11 @@ void SystemTimeToAprExpTime(apr_exploded_time_t *xt, SYSTEMTIME *tm)
/* Bias = UTC - local time in minutes
* tm_gmtoff is seconds east of UTC
*/
- xt->tm_gmtoff = tz.Bias * 60;
+ xt->tm_gmtoff = tz.Bias * -60;
break;
case TIME_ZONE_ID_DAYLIGHT:
xt->tm_isdst = 1;
- xt->tm_gmtoff = tz.Bias * 60;
+ xt->tm_gmtoff = tz.Bias * -60;
break;
default:
xt->tm_isdst = 0;