Revert "Upgrade timelib to 2017.05beta7"

This reverts commit bdd56f3107.
This commit is contained in:
Derick Rethans 2017-08-16 15:19:18 +01:00
parent 8af70958fc
commit 60a6feed07
49 changed files with 12243 additions and 14971 deletions

View file

@ -1,7 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2015-2017 Derick Rethans Copyright (c) 2015 Derick Rethans
Copyright (c) 2017 MongoDB, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -26,15 +26,15 @@
| Schlyter, who wrote this in December 1992 | | Schlyter, who wrote this in December 1992 |
*/ */
#include "timelib.h"
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include "timelib.h"
#define days_since_2000_Jan_0(y,m,d) \ #define days_since_2000_Jan_0(y,m,d) \
(367L*(y)-((7*((y)+(((m)+9)/12)))/4)+((275*(m))/9)+(d)-730530L) (367L*(y)-((7*((y)+(((m)+9)/12)))/4)+((275*(m))/9)+(d)-730530L)
#ifndef PI #ifndef PI
# define PI 3.1415926535897932384 #define PI 3.1415926535897932384
#endif #endif
#define RADEG ( 180.0 / PI ) #define RADEG ( 180.0 / PI )
@ -230,8 +230,7 @@ int timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat,
t_loc->i = t_loc->s = 0; t_loc->i = t_loc->s = 0;
timelib_update_ts(t_loc, NULL); timelib_update_ts(t_loc, NULL);
/* Calculate TS belonging to UTC 00:00 of the current day, for input into /* Calculate TS belonging to UTC 00:00 of the current day */
* the algorithm */
t_utc = timelib_time_ctor(); t_utc = timelib_time_ctor();
t_utc->y = t_loc->y; t_utc->y = t_loc->y;
t_utc->m = t_loc->m; t_utc->m = t_loc->m;
@ -240,8 +239,8 @@ int timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat,
timelib_update_ts(t_utc, NULL); timelib_update_ts(t_utc, NULL);
/* Compute d of 12h local mean solar time */ /* Compute d of 12h local mean solar time */
timestamp = t_utc->sse; timestamp = t_loc->sse;
d = timelib_ts_to_j2000(timestamp) + 2 - lon/360.0; d = timelib_ts_to_juliandate(timestamp) - lon/360.0;
/* Compute local sidereal time of this moment */ /* Compute local sidereal time of this moment */
sidtime = astro_revolution(astro_GMST0(d) + 180.0 + lon); sidtime = astro_revolution(astro_GMST0(d) + 180.0 + lon);
@ -296,18 +295,14 @@ int timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat,
return rc; return rc;
} }
double timelib_ts_to_julianday(timelib_sll ts) double timelib_ts_to_juliandate(timelib_sll ts)
{ {
double tmp; double tmp;
tmp = (double) ts; tmp = ts;
tmp /= (double) 86400; tmp /= 86400;
tmp += (double) 2440587.5; tmp += 2440587.5;
tmp -= 2451543;
return tmp; return tmp;
} }
double timelib_ts_to_j2000(timelib_sll ts)
{
return timelib_ts_to_julianday(ts) - 2451545;
}

View file

@ -23,7 +23,6 @@
*/ */
#include "timelib.h" #include "timelib.h"
#include "timelib_private.h"
static int m_table_common[13] = { -1, 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 }; /* 1 = jan */ static int m_table_common[13] = { -1, 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 }; /* 1 = jan */
static int m_table_leap[13] = { -1, 6, 2, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 }; /* 1 = jan */ static int m_table_leap[13] = { -1, 6, 2, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 }; /* 1 = jan */
@ -138,71 +137,17 @@ void timelib_isoweek_from_date(timelib_sll y, timelib_sll m, timelib_sll d, time
} }
} }
void timelib_isodate_from_date(timelib_sll y, timelib_sll m, timelib_sll d, timelib_sll *iy, timelib_sll *iw, timelib_sll *id) timelib_sll timelib_daynr_from_weeknr(timelib_sll y, timelib_sll w, timelib_sll d)
{
timelib_isoweek_from_date(y, m, d, iw, iy);
*id = timelib_day_of_week_ex(y, m, d, 1);
}
static timelib_sll timelib_daynr_from_weeknr_ex(timelib_sll iy, timelib_sll iw, timelib_sll id, timelib_sll *y)
{ {
timelib_sll dow, day; timelib_sll dow, day;
/* Figure out the dayofweek for y-1-1 */ /* Figure out the dayofweek for y-1-1 */
dow = timelib_day_of_week(iy, 1, 1); dow = timelib_day_of_week(y, 1, 1);
/* then use that to figure out the offset for day 1 of week 1 */ /* then use that to figure out the offset for day 1 of week 1 */
day = 0 - (dow > 4 ? dow - 7 : dow); day = 0 - (dow > 4 ? dow - 7 : dow);
/* and adjust the year to the natural year if we need to */
*y = (iw == 1 && day < 0 && id < dow) ? iy - 1 : iy;
/* Add weeks and days */ /* Add weeks and days */
return day + ((iw - 1) * 7) + id; return day + ((w - 1) * 7) + d;
}
timelib_sll timelib_daynr_from_weeknr(timelib_sll iy, timelib_sll iw, timelib_sll id)
{
timelib_sll dummy_iso_year;
return timelib_daynr_from_weeknr_ex(iy, iw, id, &dummy_iso_year);
}
void timelib_date_from_isodate(timelib_sll iy, timelib_sll iw, timelib_sll id, timelib_sll *y, timelib_sll *m, timelib_sll *d)
{
timelib_sll daynr = timelib_daynr_from_weeknr_ex(iy, iw, id, y) + 1;
int *table;
*m = 0;
if (daynr <= 0) {
*y += 1;
}
if (timelib_is_leap(*y)) {
table = ml_table_leap;
if (daynr > 366) {
*y += 1;
daynr -= 366;
}
} else {
table = ml_table_common;
if (daynr > 365) {
*y += 1;
daynr -= 365;
}
}
do {
daynr -= table[*m];
(*m)++;
} while (daynr > table[*m]);
if (daynr <= 0) {
daynr += 31;
*y -= 1;
*m = 12;
}
*d = daynr;
} }
int timelib_valid_time(timelib_sll h, timelib_sll i, timelib_sll s) int timelib_valid_time(timelib_sll h, timelib_sll i, timelib_sll s)

View file

@ -1,42 +1,42 @@
{ "sst", 0, -660 * 60, "Pacific/Apia" }, { "sst", 0, -660, "Pacific/Apia" },
{ "hst", 0, -600 * 60, "Pacific/Honolulu" }, { "hst", 0, -600, "Pacific/Honolulu" },
{ "akst", 0, -540 * 60, "America/Anchorage" }, { "akst", 0, -540, "America/Anchorage" },
{ "akdt", 1, -480 * 60, "America/Anchorage" }, { "akdt", 1, -480, "America/Anchorage" },
{ "pst", 0, -480 * 60, "America/Los_Angeles" }, { "pst", 0, -480, "America/Los_Angeles" },
{ "pdt", 1, -420 * 60, "America/Los_Angeles" }, { "pdt", 1, -420, "America/Los_Angeles" },
{ "mst", 0, -420 * 60, "America/Denver" }, { "mst", 0, -420, "America/Denver" },
{ "mdt", 1, -360 * 60, "America/Denver" }, { "mdt", 1, -360, "America/Denver" },
{ "cst", 0, -360 * 60, "America/Chicago" }, { "cst", 0, -360, "America/Chicago" },
{ "cdt", 1, -300 * 60, "America/Chicago" }, { "cdt", 1, -300, "America/Chicago" },
{ "est", 0, -300 * 60, "America/New_York" }, { "est", 0, -300, "America/New_York" },
{ "vet", 0, -270 * 60, "America/Caracas" }, { "vet", 0, -270, "America/Caracas" },
{ "edt", 1, -240 * 60, "America/New_York" }, { "edt", 1, -240, "America/New_York" },
{ "ast", 0, -240 * 60, "America/Halifax" }, { "ast", 0, -240, "America/Halifax" },
{ "adt", 1, -180 * 60, "America/Halifax" }, { "adt", 1, -180, "America/Halifax" },
{ "brt", 0, -180 * 60, "America/Sao_Paulo" }, { "brt", 0, -180, "America/Sao_Paulo" },
{ "brst", 1, -120 * 60, "America/Sao_Paulo" }, { "brst", 1, -120, "America/Sao_Paulo" },
{ "azost", 0, -60 * 60, "Atlantic/Azores" }, { "azost", 0, -60, "Atlantic/Azores" },
{ "azodt", 1, 0 * 60, "Atlantic/Azores" }, { "azodt", 1, 0, "Atlantic/Azores" },
{ "gmt", 0, 0 * 60, "Europe/London" }, { "gmt", 0, 0, "Europe/London" },
{ "bst", 1, 60 * 60, "Europe/London" }, { "bst", 1, 60, "Europe/London" },
{ "cet", 0, 60 * 60, "Europe/Paris" }, { "cet", 0, 60, "Europe/Paris" },
{ "cest", 1, 120 * 60, "Europe/Paris" }, { "cest", 1, 120, "Europe/Paris" },
{ "eet", 0, 120 * 60, "Europe/Helsinki" }, { "eet", 0, 120, "Europe/Helsinki" },
{ "eest", 1, 180 * 60, "Europe/Helsinki" }, { "eest", 1, 180, "Europe/Helsinki" },
{ "msk", 0, 180 * 60, "Europe/Moscow" }, { "msk", 0, 180, "Europe/Moscow" },
{ "msd", 1, 240 * 60, "Europe/Moscow" }, { "msd", 1, 240, "Europe/Moscow" },
{ "gst", 0, 240 * 60, "Asia/Dubai" }, { "gst", 0, 240, "Asia/Dubai" },
{ "pkt", 0, 300 * 60, "Asia/Karachi" }, { "pkt", 0, 300, "Asia/Karachi" },
{ "ist", 0, 330 * 60, "Asia/Kolkata" }, { "ist", 0, 330, "Asia/Kolkata" },
{ "npt", 0, 345 * 60, "Asia/Katmandu" }, { "npt", 0, 345, "Asia/Katmandu" },
{ "yekt", 1, 360 * 60, "Asia/Yekaterinburg" }, { "yekt", 1, 360, "Asia/Yekaterinburg" },
{ "novst", 1, 420 * 60, "Asia/Novosibirsk" }, { "novst", 1, 420, "Asia/Novosibirsk" },
{ "krat", 0, 420 * 60, "Asia/Krasnoyarsk" }, { "krat", 0, 420, "Asia/Krasnoyarsk" },
{ "cst", 0, 480 * 60, "Asia/Shanghai" }, { "cst", 0, 480, "Asia/Shanghai" },
{ "krast", 1, 480 * 60, "Asia/Krasnoyarsk" }, { "krast", 1, 480, "Asia/Krasnoyarsk" },
{ "jst", 0, 540 * 60, "Asia/Tokyo" }, { "jst", 0, 540, "Asia/Tokyo" },
{ "est", 0, 600 * 60, "Australia/Melbourne" }, { "est", 0, 600, "Australia/Melbourne" },
{ "cst", 1, 630 * 60, "Australia/Adelaide" }, { "cst", 1, 630, "Australia/Adelaide" },
{ "est", 1, 660 * 60, "Australia/Melbourne" }, { "est", 1, 660, "Australia/Melbourne" },
{ "nzst", 0, 720 * 60, "Pacific/Auckland" }, { "nzst", 0, 720, "Pacific/Auckland" },
{ "nzdt", 1, 780 * 60, "Pacific/Auckland" }, { "nzdt", 1, 780, "Pacific/Auckland" },

View file

@ -23,7 +23,6 @@
*/ */
#include "timelib.h" #include "timelib.h"
#include "timelib_private.h"
#include <math.h> #include <math.h>
timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two) timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
@ -66,7 +65,6 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
rt->h = two->h - one->h; rt->h = two->h - one->h;
rt->i = two->i - one->i; rt->i = two->i - one->i;
rt->s = two->s - one->s; rt->s = two->s - one->s;
rt->us = two->us - one->us;
if (one_backup.dst == 0 && two_backup.dst == 1 && two->sse >= one->sse + 86400 - dst_corr) { if (one_backup.dst == 0 && two_backup.dst == 1 && two->sse >= one->sse + 86400 - dst_corr) {
rt->h += dst_h_corr; rt->h += dst_h_corr;
rt->i += dst_m_corr; rt->i += dst_m_corr;
@ -112,7 +110,6 @@ timelib_time *timelib_add(timelib_time *old_time, timelib_rel_time *interval)
t->relative.h = interval->h * bias; t->relative.h = interval->h * bias;
t->relative.i = interval->i * bias; t->relative.i = interval->i * bias;
t->relative.s = interval->s * bias; t->relative.s = interval->s * bias;
t->relative.us = interval->us * bias;
} }
t->have_relative = 1; t->have_relative = 1;
t->sse_uptodate = 0; t->sse_uptodate = 0;
@ -148,7 +145,6 @@ timelib_time *timelib_sub(timelib_time *old_time, timelib_rel_time *interval)
t->relative.h = 0 - (interval->h * bias); t->relative.h = 0 - (interval->h * bias);
t->relative.i = 0 - (interval->i * bias); t->relative.i = 0 - (interval->i * bias);
t->relative.s = 0 - (interval->s * bias); t->relative.s = 0 - (interval->s * bias);
t->relative.us = 0 - (interval->us * bias);
t->have_relative = 1; t->have_relative = 1;
t->sse_uptodate = 0; t->sse_uptodate = 0;

File diff suppressed because it is too large Load diff

View file

@ -25,12 +25,21 @@
/* $Id$ */ /* $Id$ */
#include "timelib.h" #include "timelib.h"
#include "timelib_private.h"
#include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
#include <assert.h> #include <assert.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#if defined(_MSC_VER) #if defined(_MSC_VER)
# define strtoll(s, f, b) _atoi64(s) # define strtoll(s, f, b) _atoi64(s)
#elif !defined(HAVE_STRTOLL) #elif !defined(HAVE_STRTOLL)
@ -41,6 +50,17 @@
# endif # endif
#endif #endif
#define TIMELIB_UNSET -99999
#define TIMELIB_SECOND 1
#define TIMELIB_MINUTE 2
#define TIMELIB_HOUR 3
#define TIMELIB_DAY 4
#define TIMELIB_MONTH 5
#define TIMELIB_YEAR 6
#define TIMELIB_WEEKDAY 7
#define TIMELIB_SPECIAL 8
#define EOI 257 #define EOI 257
#define TIME 258 #define TIME 258
#define DATE 259 #define DATE 259
@ -92,14 +112,14 @@ typedef unsigned char uchar;
#define timelib_string_free timelib_free #define timelib_string_free timelib_free
#define TIMELIB_HAVE_TIME() { if (s->time->have_time) { add_error(s, TIMELIB_ERR_DOUBLE_TIME, "Double time specification"); timelib_string_free(str); return TIMELIB_ERROR; } else { s->time->have_time = 1; s->time->h = 0; s->time->i = 0; s->time->s = 0; s->time->us = 0; } } #define TIMELIB_HAVE_TIME() { if (s->time->have_time) { add_error(s, "Double time specification"); timelib_string_free(str); return TIMELIB_ERROR; } else { s->time->have_time = 1; s->time->h = 0; s->time->i = 0; s->time->s = 0; s->time->f = 0; } }
#define TIMELIB_UNHAVE_TIME() { s->time->have_time = 0; s->time->h = 0; s->time->i = 0; s->time->s = 0; s->time->us = 0; } #define TIMELIB_UNHAVE_TIME() { s->time->have_time = 0; s->time->h = 0; s->time->i = 0; s->time->s = 0; s->time->f = 0; }
#define TIMELIB_HAVE_DATE() { if (s->time->have_date) { add_error(s, TIMELIB_ERR_DOUBLE_DATE, "Double date specification"); timelib_string_free(str); return TIMELIB_ERROR; } else { s->time->have_date = 1; } } #define TIMELIB_HAVE_DATE() { if (s->time->have_date) { add_error(s, "Double date specification"); timelib_string_free(str); return TIMELIB_ERROR; } else { s->time->have_date = 1; } }
#define TIMELIB_UNHAVE_DATE() { s->time->have_date = 0; s->time->d = 0; s->time->m = 0; s->time->y = 0; } #define TIMELIB_UNHAVE_DATE() { s->time->have_date = 0; s->time->d = 0; s->time->m = 0; s->time->y = 0; }
#define TIMELIB_HAVE_RELATIVE() { s->time->have_relative = 1; } #define TIMELIB_HAVE_RELATIVE() { s->time->have_relative = 1; }
#define TIMELIB_HAVE_WEEKDAY_RELATIVE() { s->time->have_relative = 1; s->time->relative.have_weekday_relative = 1; } #define TIMELIB_HAVE_WEEKDAY_RELATIVE() { s->time->have_relative = 1; s->time->relative.have_weekday_relative = 1; }
#define TIMELIB_HAVE_SPECIAL_RELATIVE() { s->time->have_relative = 1; s->time->relative.have_special_relative = 1; } #define TIMELIB_HAVE_SPECIAL_RELATIVE() { s->time->have_relative = 1; s->time->relative.have_special_relative = 1; }
#define TIMELIB_HAVE_TZ() { s->cur = cursor; if (s->time->have_zone) { s->time->have_zone > 1 ? add_error(s, TIMELIB_ERR_DOUBLE_TZ, "Double timezone specification") : add_warning(s, TIMELIB_WARN_DOUBLE_TZ, "Double timezone specification"); timelib_string_free(str); s->time->have_zone++; return TIMELIB_ERROR; } else { s->time->have_zone++; } } #define TIMELIB_HAVE_TZ() { s->cur = cursor; if (s->time->have_zone) { s->time->have_zone > 1 ? add_error(s, "Double timezone specification") : add_warning(s, "Double timezone specification"); timelib_string_free(str); s->time->have_zone++; return TIMELIB_ERROR; } else { s->time->have_zone++; } }
#define TIMELIB_INIT s->cur = cursor; str = timelib_string(s); ptr = str #define TIMELIB_INIT s->cur = cursor; str = timelib_string(s); ptr = str
#define TIMELIB_DEINIT timelib_string_free(str) #define TIMELIB_DEINIT timelib_string_free(str)
@ -125,6 +145,8 @@ typedef unsigned char uchar;
#define YYDEBUG(s,c) #define YYDEBUG(s,c)
#endif #endif
#include "timelib_structs.h"
typedef struct timelib_elems { typedef struct timelib_elems {
unsigned int c; /* Number of elements */ unsigned int c; /* Number of elements */
char **v; /* Values */ char **v; /* Values */
@ -153,33 +175,21 @@ typedef struct _timelib_relunit {
} timelib_relunit; } timelib_relunit;
/* The timezone table. */ /* The timezone table. */
static const timelib_tz_lookup_table timelib_timezone_lookup[] = { const static timelib_tz_lookup_table timelib_timezone_lookup[] = {
#include "timezonemap.h" #include "timezonemap.h"
{ NULL, 0, 0, NULL }, { NULL, 0, 0, NULL },
}; };
static const timelib_tz_lookup_table timelib_timezone_fallbackmap[] = { const static timelib_tz_lookup_table timelib_timezone_fallbackmap[] = {
#include "fallbackmap.h" #include "fallbackmap.h"
{ NULL, 0, 0, NULL }, { NULL, 0, 0, NULL },
}; };
static const timelib_tz_lookup_table timelib_timezone_utc[] = { const static timelib_tz_lookup_table timelib_timezone_utc[] = {
{ "utc", 0, 0, "UTC" }, { "utc", 0, 0, "UTC" },
}; };
static timelib_relunit const timelib_relunit_lookup[] = { static timelib_relunit const timelib_relunit_lookup[] = {
{ "ms", TIMELIB_MICROSEC, 1000 },
{ "msec", TIMELIB_MICROSEC, 1000 },
{ "msecs", TIMELIB_MICROSEC, 1000 },
{ "millisecond", TIMELIB_MICROSEC, 1000 },
{ "milliseconds", TIMELIB_MICROSEC, 1000 },
{ "µs", TIMELIB_MICROSEC, 1 },
{ "usec", TIMELIB_MICROSEC, 1 },
{ "usecs", TIMELIB_MICROSEC, 1 },
{ "µsec", TIMELIB_MICROSEC, 1 },
{ "µsecs", TIMELIB_MICROSEC, 1 },
{ "microsecond", TIMELIB_MICROSEC, 1 },
{ "microseconds", TIMELIB_MICROSEC, 1 },
{ "sec", TIMELIB_SECOND, 1 }, { "sec", TIMELIB_SECOND, 1 },
{ "secs", TIMELIB_SECOND, 1 }, { "secs", TIMELIB_SECOND, 1 },
{ "second", TIMELIB_SECOND, 1 }, { "second", TIMELIB_SECOND, 1 },
@ -332,41 +342,37 @@ uchar *fill(Scanner *s, uchar *cursor){
} }
#endif #endif
static void add_warning(Scanner *s, int error_code, char *error) static void add_warning(Scanner *s, char *error)
{ {
s->errors->warning_count++; s->errors->warning_count++;
s->errors->warning_messages = timelib_realloc(s->errors->warning_messages, s->errors->warning_count * sizeof(timelib_error_message)); s->errors->warning_messages = timelib_realloc(s->errors->warning_messages, s->errors->warning_count * sizeof(timelib_error_message));
s->errors->warning_messages[s->errors->warning_count - 1].error_code = error_code;
s->errors->warning_messages[s->errors->warning_count - 1].position = s->tok ? s->tok - s->str : 0; s->errors->warning_messages[s->errors->warning_count - 1].position = s->tok ? s->tok - s->str : 0;
s->errors->warning_messages[s->errors->warning_count - 1].character = s->tok ? *s->tok : 0; s->errors->warning_messages[s->errors->warning_count - 1].character = s->tok ? *s->tok : 0;
s->errors->warning_messages[s->errors->warning_count - 1].message = timelib_strdup(error); s->errors->warning_messages[s->errors->warning_count - 1].message = timelib_strdup(error);
} }
static void add_error(Scanner *s, int error_code, char *error) static void add_error(Scanner *s, char *error)
{ {
s->errors->error_count++; s->errors->error_count++;
s->errors->error_messages = timelib_realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message)); s->errors->error_messages = timelib_realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message));
s->errors->error_messages[s->errors->error_count - 1].error_code = error_code;
s->errors->error_messages[s->errors->error_count - 1].position = s->tok ? s->tok - s->str : 0; s->errors->error_messages[s->errors->error_count - 1].position = s->tok ? s->tok - s->str : 0;
s->errors->error_messages[s->errors->error_count - 1].character = s->tok ? *s->tok : 0; s->errors->error_messages[s->errors->error_count - 1].character = s->tok ? *s->tok : 0;
s->errors->error_messages[s->errors->error_count - 1].message = timelib_strdup(error); s->errors->error_messages[s->errors->error_count - 1].message = timelib_strdup(error);
} }
static void add_pbf_warning(Scanner *s, int error_code, char *error, char *sptr, char *cptr) static void add_pbf_warning(Scanner *s, char *error, char *sptr, char *cptr)
{ {
s->errors->warning_count++; s->errors->warning_count++;
s->errors->warning_messages = timelib_realloc(s->errors->warning_messages, s->errors->warning_count * sizeof(timelib_error_message)); s->errors->warning_messages = timelib_realloc(s->errors->warning_messages, s->errors->warning_count * sizeof(timelib_error_message));
s->errors->warning_messages[s->errors->warning_count - 1].error_code = error_code;
s->errors->warning_messages[s->errors->warning_count - 1].position = cptr - sptr; s->errors->warning_messages[s->errors->warning_count - 1].position = cptr - sptr;
s->errors->warning_messages[s->errors->warning_count - 1].character = *cptr; s->errors->warning_messages[s->errors->warning_count - 1].character = *cptr;
s->errors->warning_messages[s->errors->warning_count - 1].message = timelib_strdup(error); s->errors->warning_messages[s->errors->warning_count - 1].message = timelib_strdup(error);
} }
static void add_pbf_error(Scanner *s, int error_code, char *error, char *sptr, char *cptr) static void add_pbf_error(Scanner *s, char *error, char *sptr, char *cptr)
{ {
s->errors->error_count++; s->errors->error_count++;
s->errors->error_messages = timelib_realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message)); s->errors->error_messages = timelib_realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message));
s->errors->error_messages[s->errors->error_count - 1].error_code = error_code;
s->errors->error_messages[s->errors->error_count - 1].position = cptr - sptr; s->errors->error_messages[s->errors->error_count - 1].position = cptr - sptr;
s->errors->error_messages[s->errors->error_count - 1].character = *cptr; s->errors->error_messages[s->errors->error_count - 1].character = *cptr;
s->errors->error_messages[s->errors->error_count - 1].message = timelib_strdup(error); s->errors->error_messages[s->errors->error_count - 1].message = timelib_strdup(error);
@ -486,7 +492,7 @@ static void timelib_skip_day_suffix(char **ptr)
} }
} }
static timelib_sll timelib_get_frac_nr(char **ptr, int max_length) static double timelib_get_frac_nr(char **ptr, int max_length)
{ {
char *begin, *end, *str; char *begin, *end, *str;
double tmp_nr = TIMELIB_UNSET; double tmp_nr = TIMELIB_UNSET;
@ -504,9 +510,12 @@ static timelib_sll timelib_get_frac_nr(char **ptr, int max_length)
++len; ++len;
} }
end = *ptr; end = *ptr;
str = timelib_calloc(1, end - begin); str = timelib_calloc(1, end - begin + 1);
memcpy(str, begin + 1, end - begin - 1); memcpy(str, begin, end - begin);
tmp_nr = strtod(str, NULL) * pow(10, 7 - (end - begin)); if (str[0] == ':') {
str[0] = '.';
}
tmp_nr = strtod(str, NULL);
timelib_free(str); timelib_free(str);
return tmp_nr; return tmp_nr;
} }
@ -646,13 +655,12 @@ static void timelib_set_relative(char **ptr, timelib_sll amount, int behavior, S
} }
switch (relunit->unit) { switch (relunit->unit) {
case TIMELIB_MICROSEC: s->time->relative.us += amount * relunit->multiplier; break; case TIMELIB_SECOND: s->time->relative.s += amount * relunit->multiplier; break;
case TIMELIB_SECOND: s->time->relative.s += amount * relunit->multiplier; break; case TIMELIB_MINUTE: s->time->relative.i += amount * relunit->multiplier; break;
case TIMELIB_MINUTE: s->time->relative.i += amount * relunit->multiplier; break; case TIMELIB_HOUR: s->time->relative.h += amount * relunit->multiplier; break;
case TIMELIB_HOUR: s->time->relative.h += amount * relunit->multiplier; break; case TIMELIB_DAY: s->time->relative.d += amount * relunit->multiplier; break;
case TIMELIB_DAY: s->time->relative.d += amount * relunit->multiplier; break; case TIMELIB_MONTH: s->time->relative.m += amount * relunit->multiplier; break;
case TIMELIB_MONTH: s->time->relative.m += amount * relunit->multiplier; break; case TIMELIB_YEAR: s->time->relative.y += amount * relunit->multiplier; break;
case TIMELIB_YEAR: s->time->relative.y += amount * relunit->multiplier; break;
case TIMELIB_WEEKDAY: case TIMELIB_WEEKDAY:
TIMELIB_HAVE_WEEKDAY_RELATIVE(); TIMELIB_HAVE_WEEKDAY_RELATIVE();
@ -670,7 +678,7 @@ static void timelib_set_relative(char **ptr, timelib_sll amount, int behavior, S
} }
} }
static const timelib_tz_lookup_table* abbr_search(const char *word, timelib_long gmtoffset, int isdst) const static timelib_tz_lookup_table* abbr_search(const char *word, timelib_long gmtoffset, int isdst)
{ {
int first_found = 0; int first_found = 0;
const timelib_tz_lookup_table *tp, *first_found_elem = NULL; const timelib_tz_lookup_table *tp, *first_found_elem = NULL;
@ -701,7 +709,7 @@ static const timelib_tz_lookup_table* abbr_search(const char *word, timelib_long
/* Still didn't find anything, let's find the zone solely based on /* Still didn't find anything, let's find the zone solely based on
* offset/isdst then */ * offset/isdst then */
for (fmp = timelib_timezone_fallbackmap; fmp->name; fmp++) { for (fmp = timelib_timezone_fallbackmap; fmp->name; fmp++) {
if (fmp->gmtoffset == gmtoffset && fmp->type == isdst) { if ((fmp->gmtoffset * 60) == gmtoffset && fmp->type == isdst) {
return fmp; return fmp;
} }
} }
@ -723,9 +731,9 @@ static timelib_long timelib_lookup_abbr(char **ptr, int *dst, char **tz_abbr, in
memcpy(word, begin, end - begin); memcpy(word, begin, end - begin);
if ((tp = abbr_search(word, -1, 0))) { if ((tp = abbr_search(word, -1, 0))) {
value = tp->gmtoffset; value = -tp->gmtoffset / 60;
*dst = tp->type; *dst = tp->type;
value -= tp->type * 3600; value += tp->type * 60;
*found = 1; *found = 1;
} else { } else {
*found = 0; *found = 0;
@ -735,42 +743,6 @@ static timelib_long timelib_lookup_abbr(char **ptr, int *dst, char **tz_abbr, in
return value; return value;
} }
#define sHOUR(a) (int)(a * 3600)
#define sMIN(a) (int)(a * 60)
static timelib_long timelib_parse_tz_cor(char **ptr)
{
char *begin = *ptr, *end;
timelib_long tmp;
while (isdigit(**ptr) || **ptr == ':') {
++*ptr;
}
end = *ptr;
switch (end - begin) {
case 1: /* H */
case 2: /* HH */
return sHOUR(strtol(begin, NULL, 10));
break;
case 3: /* H:M */
case 4: /* H:MM, HH:M, HHMM */
if (begin[1] == ':') {
tmp = sHOUR(strtol(begin, NULL, 10)) + sMIN(strtol(begin + 2, NULL, 10));
return tmp;
} else if (begin[2] == ':') {
tmp = sHOUR(strtol(begin, NULL, 10)) + sMIN(strtol(begin + 3, NULL, 10));
return tmp;
} else {
tmp = strtol(begin, NULL, 10);
return sHOUR(tmp / 100) + sMIN(tmp % 100);
}
case 5: /* HH:MM */
tmp = sHOUR(strtol(begin, NULL, 10)) + sMIN(strtol(begin + 3, NULL, 10));
return tmp;
}
return 0;
}
timelib_long timelib_parse_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_wrapper) timelib_long timelib_parse_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_wrapper)
{ {
timelib_tzinfo *res; timelib_tzinfo *res;
@ -791,7 +763,7 @@ timelib_long timelib_parse_zone(char **ptr, int *dst, timelib_time *t, int *tz_n
*tz_not_found = 0; *tz_not_found = 0;
t->dst = 0; t->dst = 0;
retval = timelib_parse_tz_cor(ptr); retval = -1 * timelib_parse_tz_cor(ptr);
} else if (**ptr == '-') { } else if (**ptr == '-') {
++*ptr; ++*ptr;
t->is_localtime = 1; t->is_localtime = 1;
@ -799,7 +771,7 @@ timelib_long timelib_parse_zone(char **ptr, int *dst, timelib_time *t, int *tz_n
*tz_not_found = 0; *tz_not_found = 0;
t->dst = 0; t->dst = 0;
retval = -1 * timelib_parse_tz_cor(ptr); retval = timelib_parse_tz_cor(ptr);
} else { } else {
int found = 0; int found = 0;
timelib_long offset = 0; timelib_long offset = 0;
@ -816,9 +788,7 @@ timelib_long timelib_parse_zone(char **ptr, int *dst, timelib_time *t, int *tz_n
/* Otherwise, we look if we have a TimeZone identifier */ /* Otherwise, we look if we have a TimeZone identifier */
if (!found || strcmp("UTC", tz_abbr) == 0) { if (!found || strcmp("UTC", tz_abbr) == 0) {
int dummy_error_code; if ((res = tz_wrapper(tz_abbr, tzdb)) != NULL) {
if ((res = tz_wrapper(tz_abbr, tzdb, &dummy_error_code)) != NULL) {
t->tz_info = res; t->tz_info = res;
t->zone_type = TIMELIB_ZONETYPE_ID; t->zone_type = TIMELIB_ZONETYPE_ID;
found++; found++;
@ -947,15 +917,14 @@ isoweek = year4 "-"? "W" weekofyear;
exif = year4 ":" monthlz ":" daylz " " hour24lz ":" minutelz ":" secondlz; exif = year4 ":" monthlz ":" daylz " " hour24lz ":" minutelz ":" secondlz;
firstdayof = 'first day of'; firstdayof = 'first day of';
lastdayof = 'last day of'; lastdayof = 'last day of';
backof = 'back of ' hour24 (space? meridian)?; backof = 'back of ' hour24 space? meridian?;
frontof = 'front of ' hour24 (space? meridian)?; frontof = 'front of ' hour24 space? meridian?;
/* Common Log Format: 10/Oct/2000:13:55:36 -0700 */ /* Common Log Format: 10/Oct/2000:13:55:36 -0700 */
clf = day "/" monthabbr "/" year4 ":" hour24lz ":" minutelz ":" secondlz space tzcorrection; clf = day "/" monthabbr "/" year4 ":" hour24lz ":" minutelz ":" secondlz space tzcorrection;
/* Timestamp format: @1126396800 */ /* Timestamp format: @1126396800 */
timestamp = "@" "-"? [0-9]+; timestamp = "@" "-"? [0-9]+;
timestampms = "@" "-"? [0-9]+ "." [0-9]{6};
/* To fix some ambiguities */ /* To fix some ambiguities */
dateshortwithtimeshort12 = datenoyear timeshort12; dateshortwithtimeshort12 = datenoyear timeshort12;
@ -969,7 +938,7 @@ dateshortwithtimelongtz = datenoyear iso8601normtz;
*/ */
reltextnumber = 'first'|'second'|'third'|'fourth'|'fifth'|'sixth'|'seventh'|'eight'|'eighth'|'ninth'|'tenth'|'eleventh'|'twelfth'; reltextnumber = 'first'|'second'|'third'|'fourth'|'fifth'|'sixth'|'seventh'|'eight'|'eighth'|'ninth'|'tenth'|'eleventh'|'twelfth';
reltexttext = 'next'|'last'|'previous'|'this'; reltexttext = 'next'|'last'|'previous'|'this';
reltextunit = 'ms' | 'µs' | (('msec'|'millisecond'|'µsec'|'microsecond'|'usec'|'sec'|'second'|'min'|'minute'|'hour'|'day'|'fortnight'|'forthnight'|'month'|'year') 's'?) | 'weeks' | daytext; reltextunit = (('sec'|'second'|'min'|'minute'|'hour'|'day'|'fortnight'|'forthnight'|'month'|'year') 's'?) | 'weeks' | daytext;
relnumber = ([+-]*[ \t]*[0-9]+); relnumber = ([+-]*[ \t]*[0-9]+);
relative = relnumber space? (reltextunit | 'week' ); relative = relnumber space? (reltextunit | 'week' );
@ -1052,7 +1021,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
s->time->m = 1; s->time->m = 1;
s->time->d = 1; s->time->d = 1;
s->time->h = s->time->i = s->time->s = 0; s->time->h = s->time->i = s->time->s = 0;
s->time->us = 0; s->time->f = 0.0;
s->time->relative.s += i; s->time->relative.s += i;
s->time->is_localtime = 1; s->time->is_localtime = 1;
s->time->zone_type = TIMELIB_ZONETYPE_OFFSET; s->time->zone_type = TIMELIB_ZONETYPE_OFFSET;
@ -1063,34 +1032,6 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
return TIMELIB_RELATIVE; return TIMELIB_RELATIVE;
} }
timestampms
{
timelib_ull i, us;
TIMELIB_INIT;
TIMELIB_HAVE_RELATIVE();
TIMELIB_UNHAVE_DATE();
TIMELIB_UNHAVE_TIME();
TIMELIB_HAVE_TZ();
i = timelib_get_unsigned_nr((char **) &ptr, 24);
us = timelib_get_unsigned_nr((char **) &ptr, 24);
s->time->y = 1970;
s->time->m = 1;
s->time->d = 1;
s->time->h = s->time->i = s->time->s = 0;
s->time->us = 0;
s->time->relative.s += i;
s->time->relative.us = us;
s->time->is_localtime = 1;
s->time->zone_type = TIMELIB_ZONETYPE_OFFSET;
s->time->z = 0;
s->time->dst = 0;
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
firstdayof | lastdayof firstdayof | lastdayof
{ {
DEBUG_OUTPUT("firstdayof | lastdayof"); DEBUG_OUTPUT("firstdayof | lastdayof");
@ -1181,7 +1122,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
s->time->s = timelib_get_nr((char **) &ptr, 2); s->time->s = timelib_get_nr((char **) &ptr, 2);
if (*ptr == ':' || *ptr == '.') { if (*ptr == ':' || *ptr == '.') {
s->time->us = timelib_get_frac_nr((char **) &ptr, 8); s->time->f = timelib_get_frac_nr((char **) &ptr, 8);
} }
} }
timelib_eat_spaces((char **) &ptr); timelib_eat_spaces((char **) &ptr);
@ -1202,14 +1143,14 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
s->time->s = timelib_get_nr((char **) &ptr, 2); s->time->s = timelib_get_nr((char **) &ptr, 2);
if (*ptr == '.') { if (*ptr == '.') {
s->time->us = timelib_get_frac_nr((char **) &ptr, 8); s->time->f = timelib_get_frac_nr((char **) &ptr, 8);
} }
} }
if (*ptr != '\0') { if (*ptr != '\0') {
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper); s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) { if (tz_not_found) {
add_error(s, TIMELIB_ERR_TZID_NOT_FOUND, "The timezone could not be found in the database"); add_error(s, "The timezone could not be found in the database");
} }
} }
TIMELIB_DEINIT; TIMELIB_DEINIT;
@ -1231,7 +1172,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
break; break;
default: default:
TIMELIB_DEINIT; TIMELIB_DEINIT;
add_error(s, TIMELIB_ERR_DOUBLE_TIME, "Double time specification"); add_error(s, "Double time specification");
return TIMELIB_ERROR; return TIMELIB_ERROR;
} }
s->time->have_time++; s->time->have_time++;
@ -1275,7 +1216,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
if (*ptr != '\0') { if (*ptr != '\0') {
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper); s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) { if (tz_not_found) {
add_error(s, TIMELIB_ERR_TZID_NOT_FOUND, "The timezone could not be found in the database"); add_error(s, "The timezone could not be found in the database");
} }
} }
TIMELIB_DEINIT; TIMELIB_DEINIT;
@ -1473,11 +1414,11 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
s->time->i = timelib_get_nr((char **) &ptr, 2); s->time->i = timelib_get_nr((char **) &ptr, 2);
s->time->s = timelib_get_nr((char **) &ptr, 2); s->time->s = timelib_get_nr((char **) &ptr, 2);
if (*ptr == '.') { if (*ptr == '.') {
s->time->us = timelib_get_frac_nr((char **) &ptr, 9); s->time->f = timelib_get_frac_nr((char **) &ptr, 9);
if (*ptr) { /* timezone is optional */ if (*ptr) { /* timezone is optional */
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper); s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) { if (tz_not_found) {
add_error(s, TIMELIB_ERR_TZID_NOT_FOUND, "The timezone could not be found in the database"); add_error(s, "The timezone could not be found in the database");
} }
} }
} }
@ -1580,7 +1521,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
s->time->s = timelib_get_nr((char **) &ptr, 2); s->time->s = timelib_get_nr((char **) &ptr, 2);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper); s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) { if (tz_not_found) {
add_error(s, TIMELIB_ERR_TZID_NOT_FOUND, "The timezone could not be found in the database"); add_error(s, "The timezone could not be found in the database");
} }
TIMELIB_DEINIT; TIMELIB_DEINIT;
return TIMELIB_CLF; return TIMELIB_CLF;
@ -1693,7 +1634,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
TIMELIB_HAVE_TZ(); TIMELIB_HAVE_TZ();
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper); s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) { if (tz_not_found) {
add_error(s, TIMELIB_ERR_TZID_NOT_FOUND, "The timezone could not be found in the database"); add_error(s, "The timezone could not be found in the database");
} }
TIMELIB_DEINIT; TIMELIB_DEINIT;
return TIMELIB_TIMEZONE; return TIMELIB_TIMEZONE;
@ -1714,7 +1655,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
s->time->s = timelib_get_nr((char **) &ptr, 2); s->time->s = timelib_get_nr((char **) &ptr, 2);
if (*ptr == '.') { if (*ptr == '.') {
s->time->us = timelib_get_frac_nr((char **) &ptr, 8); s->time->f = timelib_get_frac_nr((char **) &ptr, 8);
} }
} }
@ -1739,14 +1680,14 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
s->time->s = timelib_get_nr((char **) &ptr, 2); s->time->s = timelib_get_nr((char **) &ptr, 2);
if (*ptr == '.') { if (*ptr == '.') {
s->time->us = timelib_get_frac_nr((char **) &ptr, 8); s->time->f = timelib_get_frac_nr((char **) &ptr, 8);
} }
} }
if (*ptr != '\0') { if (*ptr != '\0') {
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper); s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) { if (tz_not_found) {
add_error(s, TIMELIB_ERR_TZID_NOT_FOUND, "The timezone could not be found in the database"); add_error(s, "The timezone could not be found in the database");
} }
} }
TIMELIB_DEINIT; TIMELIB_DEINIT;
@ -1782,7 +1723,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
any any
{ {
add_error(s, TIMELIB_ERR_UNEXPECTED_CHARACTER, "Unexpected character"); add_error(s, "Unexpected character");
goto std; goto std;
} }
*/ */
@ -1813,13 +1754,13 @@ timelib_time* timelib_strtotime(char *s, size_t len, struct timelib_error_contai
} }
if (e - s < 0) { if (e - s < 0) {
in.time = timelib_time_ctor(); in.time = timelib_time_ctor();
add_error(&in, TIMELIB_ERR_EMPTY_STRING, "Empty string"); add_error(&in, "Empty string");
if (errors) { if (errors) {
*errors = in.errors; *errors = in.errors;
} else { } else {
timelib_error_container_dtor(in.errors); timelib_error_container_dtor(in.errors);
} }
in.time->y = in.time->d = in.time->m = in.time->h = in.time->i = in.time->s = in.time->us = in.time->dst = in.time->z = TIMELIB_UNSET; in.time->y = in.time->d = in.time->m = in.time->h = in.time->i = in.time->s = in.time->f = in.time->dst = in.time->z = TIMELIB_UNSET;
in.time->is_localtime = in.time->zone_type = 0; in.time->is_localtime = in.time->zone_type = 0;
return in.time; return in.time;
} }
@ -1837,7 +1778,7 @@ timelib_time* timelib_strtotime(char *s, size_t len, struct timelib_error_contai
in.time->h = TIMELIB_UNSET; in.time->h = TIMELIB_UNSET;
in.time->i = TIMELIB_UNSET; in.time->i = TIMELIB_UNSET;
in.time->s = TIMELIB_UNSET; in.time->s = TIMELIB_UNSET;
in.time->us = TIMELIB_UNSET; in.time->f = TIMELIB_UNSET;
in.time->z = TIMELIB_UNSET; in.time->z = TIMELIB_UNSET;
in.time->dst = TIMELIB_UNSET; in.time->dst = TIMELIB_UNSET;
in.tzdb = tzdb; in.tzdb = tzdb;
@ -1854,11 +1795,11 @@ timelib_time* timelib_strtotime(char *s, size_t len, struct timelib_error_contai
/* do funky checking whether the parsed time was valid time */ /* do funky checking whether the parsed time was valid time */
if (in.time->have_time && !timelib_valid_time( in.time->h, in.time->i, in.time->s)) { if (in.time->have_time && !timelib_valid_time( in.time->h, in.time->i, in.time->s)) {
add_warning(&in, TIMELIB_WARN_INVALID_TIME, "The parsed time was invalid"); add_warning(&in, "The parsed time was invalid");
} }
/* do funky checking whether the parsed date was valid date */ /* do funky checking whether the parsed date was valid date */
if (in.time->have_date && !timelib_valid_date( in.time->y, in.time->m, in.time->d)) { if (in.time->have_date && !timelib_valid_date( in.time->y, in.time->m, in.time->d)) {
add_warning(&in, TIMELIB_WARN_INVALID_DATE, "The parsed date was invalid"); add_warning(&in, "The parsed date was invalid");
} }
timelib_free(in.str); timelib_free(in.str);
@ -1873,12 +1814,12 @@ timelib_time* timelib_strtotime(char *s, size_t len, struct timelib_error_contai
#define TIMELIB_CHECK_NUMBER \ #define TIMELIB_CHECK_NUMBER \
if (strchr("0123456789", *ptr) == NULL) \ if (strchr("0123456789", *ptr) == NULL) \
{ \ { \
add_pbf_error(s, TIMELIB_ERR_UNEXPECTED_DATA, "Unexpected data found.", string, begin); \ add_pbf_error(s, "Unexpected data found.", string, begin); \
} }
#define TIMELIB_CHECK_SIGNED_NUMBER \ #define TIMELIB_CHECK_SIGNED_NUMBER \
if (strchr("-0123456789", *ptr) == NULL) \ if (strchr("-0123456789", *ptr) == NULL) \
{ \ { \
add_pbf_error(s, TIMELIB_ERR_UNEXPECTED_DATA, "Unexpected data found.", string, begin); \ add_pbf_error(s, "Unexpected data found.", string, begin); \
} }
static void timelib_time_reset_fields(timelib_time *time) static void timelib_time_reset_fields(timelib_time *time)
@ -1889,7 +1830,7 @@ static void timelib_time_reset_fields(timelib_time *time)
time->m = 1; time->m = 1;
time->d = 1; time->d = 1;
time->h = time->i = time->s = 0; time->h = time->i = time->s = 0;
time->us = 0; time->f = 0.0;
time->tz_info = NULL; time->tz_info = NULL;
} }
@ -1903,7 +1844,7 @@ static void timelib_time_reset_unset_fields(timelib_time *time)
if (time->h == TIMELIB_UNSET ) time->h = 0; if (time->h == TIMELIB_UNSET ) time->h = 0;
if (time->i == TIMELIB_UNSET ) time->i = 0; if (time->i == TIMELIB_UNSET ) time->i = 0;
if (time->s == TIMELIB_UNSET ) time->s = 0; if (time->s == TIMELIB_UNSET ) time->s = 0;
if (time->us == TIMELIB_UNSET ) time->us = 0; if (time->f == TIMELIB_UNSET ) time->f = 0.0;
} }
timelib_time *timelib_parse_from_format(char *format, char *string, size_t len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper) timelib_time *timelib_parse_from_format(char *format, char *string, size_t len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper)
@ -1930,7 +1871,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
in.time->h = TIMELIB_UNSET; in.time->h = TIMELIB_UNSET;
in.time->i = TIMELIB_UNSET; in.time->i = TIMELIB_UNSET;
in.time->s = TIMELIB_UNSET; in.time->s = TIMELIB_UNSET;
in.time->us = TIMELIB_UNSET; in.time->f = TIMELIB_UNSET;
in.time->z = TIMELIB_UNSET; in.time->z = TIMELIB_UNSET;
in.time->dst = TIMELIB_UNSET; in.time->dst = TIMELIB_UNSET;
in.tzdb = tzdb; in.tzdb = tzdb;
@ -1948,7 +1889,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
tmprel = timelib_lookup_relunit((char **) &ptr); tmprel = timelib_lookup_relunit((char **) &ptr);
if (!tmprel) { if (!tmprel) {
add_pbf_error(s, TIMELIB_ERR_NO_TEXTUAL_DAY, "A textual day could not be found", string, begin); add_pbf_error(s, "A textual day could not be found", string, begin);
break; break;
} else { } else {
in.time->have_relative = 1; in.time->have_relative = 1;
@ -1962,7 +1903,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
case 'j': /* two digit day, without leading zero */ case 'j': /* two digit day, without leading zero */
TIMELIB_CHECK_NUMBER; TIMELIB_CHECK_NUMBER;
if ((s->time->d = timelib_get_nr((char **) &ptr, 2)) == TIMELIB_UNSET) { if ((s->time->d = timelib_get_nr((char **) &ptr, 2)) == TIMELIB_UNSET) {
add_pbf_error(s, TIMELIB_ERR_NO_TWO_DIGIT_DAY, "A two digit day could not be found", string, begin); add_pbf_error(s, "A two digit day could not be found", string, begin);
} }
break; break;
case 'S': /* day suffix, ignored, nor checked */ case 'S': /* day suffix, ignored, nor checked */
@ -1971,7 +1912,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
case 'z': /* day of year - resets month (0 based) - also initializes everything else to !TIMELIB_UNSET */ case 'z': /* day of year - resets month (0 based) - also initializes everything else to !TIMELIB_UNSET */
TIMELIB_CHECK_NUMBER; TIMELIB_CHECK_NUMBER;
if ((tmp = timelib_get_nr((char **) &ptr, 3)) == TIMELIB_UNSET) { if ((tmp = timelib_get_nr((char **) &ptr, 3)) == TIMELIB_UNSET) {
add_pbf_error(s, TIMELIB_ERR_NO_THREE_DIGIT_DAY_OF_YEAR, "A three digit day-of-year could not be found", string, begin); add_pbf_error(s, "A three digit day-of-year could not be found", string, begin);
} else { } else {
s->time->m = 1; s->time->m = 1;
s->time->d = tmp + 1; s->time->d = tmp + 1;
@ -1983,14 +1924,14 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
case 'n': /* two digit month, without leading zero */ case 'n': /* two digit month, without leading zero */
TIMELIB_CHECK_NUMBER; TIMELIB_CHECK_NUMBER;
if ((s->time->m = timelib_get_nr((char **) &ptr, 2)) == TIMELIB_UNSET) { if ((s->time->m = timelib_get_nr((char **) &ptr, 2)) == TIMELIB_UNSET) {
add_pbf_error(s, TIMELIB_ERR_NO_TWO_DIGIT_MONTH, "A two digit month could not be found", string, begin); add_pbf_error(s, "A two digit month could not be found", string, begin);
} }
break; break;
case 'M': /* three letter month */ case 'M': /* three letter month */
case 'F': /* full month */ case 'F': /* full month */
tmp = timelib_lookup_month((char **) &ptr); tmp = timelib_lookup_month((char **) &ptr);
if (!tmp) { if (!tmp) {
add_pbf_error(s, TIMELIB_ERR_NO_TEXTUAL_MONTH, "A textual month could not be found", string, begin); add_pbf_error(s, "A textual month could not be found", string, begin);
} else { } else {
s->time->m = tmp; s->time->m = tmp;
} }
@ -2000,7 +1941,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
int length = 0; int length = 0;
TIMELIB_CHECK_NUMBER; TIMELIB_CHECK_NUMBER;
if ((s->time->y = timelib_get_nr_ex((char **) &ptr, 2, &length)) == TIMELIB_UNSET) { if ((s->time->y = timelib_get_nr_ex((char **) &ptr, 2, &length)) == TIMELIB_UNSET) {
add_pbf_error(s, TIMELIB_ERR_NO_TWO_DIGIT_YEAR, "A two digit year could not be found", string, begin); add_pbf_error(s, "A two digit year could not be found", string, begin);
} }
TIMELIB_PROCESS_YEAR(s->time->y, length); TIMELIB_PROCESS_YEAR(s->time->y, length);
} }
@ -2008,32 +1949,32 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
case 'Y': /* four digit year */ case 'Y': /* four digit year */
TIMELIB_CHECK_NUMBER; TIMELIB_CHECK_NUMBER;
if ((s->time->y = timelib_get_nr((char **) &ptr, 4)) == TIMELIB_UNSET) { if ((s->time->y = timelib_get_nr((char **) &ptr, 4)) == TIMELIB_UNSET) {
add_pbf_error(s, TIMELIB_ERR_NO_FOUR_DIGIT_YEAR, "A four digit year could not be found", string, begin); add_pbf_error(s, "A four digit year could not be found", string, begin);
} }
break; break;
case 'g': /* two digit hour, with leading zero */ case 'g': /* two digit hour, with leading zero */
case 'h': /* two digit hour, without leading zero */ case 'h': /* two digit hour, without leading zero */
TIMELIB_CHECK_NUMBER; TIMELIB_CHECK_NUMBER;
if ((s->time->h = timelib_get_nr((char **) &ptr, 2)) == TIMELIB_UNSET) { if ((s->time->h = timelib_get_nr((char **) &ptr, 2)) == TIMELIB_UNSET) {
add_pbf_error(s, TIMELIB_ERR_NO_TWO_DIGIT_HOUR, "A two digit hour could not be found", string, begin); add_pbf_error(s, "A two digit hour could not be found", string, begin);
} }
if (s->time->h > 12) { if (s->time->h > 12) {
add_pbf_error(s, TIMELIB_ERR_HOUR_LARGER_THAN_12, "Hour can not be higher than 12", string, begin); add_pbf_error(s, "Hour can not be higher than 12", string, begin);
} }
break; break;
case 'G': /* two digit hour, with leading zero */ case 'G': /* two digit hour, with leading zero */
case 'H': /* two digit hour, without leading zero */ case 'H': /* two digit hour, without leading zero */
TIMELIB_CHECK_NUMBER; TIMELIB_CHECK_NUMBER;
if ((s->time->h = timelib_get_nr((char **) &ptr, 2)) == TIMELIB_UNSET) { if ((s->time->h = timelib_get_nr((char **) &ptr, 2)) == TIMELIB_UNSET) {
add_pbf_error(s, TIMELIB_ERR_NO_TWO_DIGIT_HOUR, "A two digit hour could not be found", string, begin); add_pbf_error(s, "A two digit hour could not be found", string, begin);
} }
break; break;
case 'a': /* am/pm/a.m./p.m. */ case 'a': /* am/pm/a.m./p.m. */
case 'A': /* AM/PM/A.M./P.M. */ case 'A': /* AM/PM/A.M./P.M. */
if (s->time->h == TIMELIB_UNSET) { if (s->time->h == TIMELIB_UNSET) {
add_pbf_error(s, TIMELIB_ERR_MERIDIAN_BEFORE_HOUR, "Meridian can only come after an hour has been found", string, begin); add_pbf_error(s, "Meridian can only come after an hour has been found", string, begin);
} else if ((tmp = timelib_meridian_with_check((char **) &ptr, s->time->h)) == TIMELIB_UNSET) { } else if ((tmp = timelib_meridian_with_check((char **) &ptr, s->time->h)) == TIMELIB_UNSET) {
add_pbf_error(s, TIMELIB_ERR_NO_MERIDIAN, "A meridian could not be found", string, begin); add_pbf_error(s, "A meridian could not be found", string, begin);
} else { } else {
s->time->h += tmp; s->time->h += tmp;
} }
@ -2046,7 +1987,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
TIMELIB_CHECK_NUMBER; TIMELIB_CHECK_NUMBER;
min = timelib_get_nr_ex((char **) &ptr, 2, &length); min = timelib_get_nr_ex((char **) &ptr, 2, &length);
if (min == TIMELIB_UNSET || length != 2) { if (min == TIMELIB_UNSET || length != 2) {
add_pbf_error(s, TIMELIB_ERR_NO_TWO_DIGIT_MINUTE, "A two digit minute could not be found", string, begin); add_pbf_error(s, "A two digit minute could not be found", string, begin);
} else { } else {
s->time->i = min; s->time->i = min;
} }
@ -2060,13 +2001,13 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
TIMELIB_CHECK_NUMBER; TIMELIB_CHECK_NUMBER;
sec = timelib_get_nr_ex((char **) &ptr, 2, &length); sec = timelib_get_nr_ex((char **) &ptr, 2, &length);
if (sec == TIMELIB_UNSET || length != 2) { if (sec == TIMELIB_UNSET || length != 2) {
add_pbf_error(s, TIMELIB_ERR_NO_TWO_DIGIT_SECOND, "A two digit second could not be found", string, begin); add_pbf_error(s, "A two digit second could not be found", string, begin);
} else { } else {
s->time->s = sec; s->time->s = sec;
} }
} }
break; break;
case 'u': /* up to six digit microsecond */ case 'u': /* up to six digit millisecond */
{ {
double f; double f;
char *tptr; char *tptr;
@ -2074,9 +2015,9 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
TIMELIB_CHECK_NUMBER; TIMELIB_CHECK_NUMBER;
tptr = ptr; tptr = ptr;
if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || (ptr - tptr < 1)) { if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || (ptr - tptr < 1)) {
add_pbf_error(s, TIMELIB_ERR_NO_SIX_DIGIT_MICROSECOND, "A six digit microsecond could not be found", string, begin); add_pbf_error(s, "A six digit millisecond could not be found", string, begin);
} else { } else {
s->time->us = (f * pow(10, 6 - (ptr - tptr))); s->time->f = (f / pow(10, (ptr - tptr)));
} }
} }
break; break;
@ -2091,6 +2032,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
s->time->m = 1; s->time->m = 1;
s->time->d = 1; s->time->d = 1;
s->time->h = s->time->i = s->time->s = 0; s->time->h = s->time->i = s->time->s = 0;
s->time->f = 0.0;
s->time->relative.s += tmp; s->time->relative.s += tmp;
s->time->is_localtime = 1; s->time->is_localtime = 1;
s->time->zone_type = TIMELIB_ZONETYPE_OFFSET; s->time->zone_type = TIMELIB_ZONETYPE_OFFSET;
@ -2106,7 +2048,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
int tz_not_found; int tz_not_found;
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper); s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) { if (tz_not_found) {
add_pbf_error(s, TIMELIB_ERR_TZID_NOT_FOUND, "The timezone could not be found in the database", string, begin); add_pbf_error(s, "The timezone could not be found in the database", string, begin);
} }
} }
break; break;
@ -2115,7 +2057,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
if (*ptr == ';' || *ptr == ':' || *ptr == '/' || *ptr == '.' || *ptr == ',' || *ptr == '-' || *ptr == '(' || *ptr == ')') { if (*ptr == ';' || *ptr == ':' || *ptr == '/' || *ptr == '.' || *ptr == ',' || *ptr == '-' || *ptr == '(' || *ptr == ')') {
++ptr; ++ptr;
} else { } else {
add_pbf_error(s, TIMELIB_ERR_NO_SEP_SYMBOL, "The separation symbol ([;:/.,-]) could not be found", string, begin); add_pbf_error(s, "The separation symbol ([;:/.,-]) could not be found", string, begin);
} }
break; break;
@ -2130,7 +2072,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
if (*ptr == *fptr) { if (*ptr == *fptr) {
++ptr; ++ptr;
} else { } else {
add_pbf_error(s, TIMELIB_ERR_NO_SEP_SYMBOL, "The separation symbol could not be found", string, begin); add_pbf_error(s, "The separation symbol could not be found", string, begin);
} }
break; break;
@ -2148,14 +2090,14 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
case '\\': /* escaped char */ case '\\': /* escaped char */
if(!fptr[1]) { if(!fptr[1]) {
add_pbf_error(s, TIMELIB_ERR_EXPECTED_ESCAPE_CHAR, "Escaped character expected", string, begin); add_pbf_error(s, "Escaped character expected", string, begin);
break; break;
} }
fptr++; fptr++;
if (*ptr == *fptr) { if (*ptr == *fptr) {
++ptr; ++ptr;
} else { } else {
add_pbf_error(s, TIMELIB_ERR_NO_ESCAPED_CHAR, "The escaped character could not be found", string, begin); add_pbf_error(s, "The escaped character could not be found", string, begin);
} }
break; break;
@ -2169,7 +2111,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
default: default:
if (*fptr != *ptr) { if (*fptr != *ptr) {
add_pbf_error(s, TIMELIB_ERR_WRONG_FORMAT_SEP, "The format separator does not match", string, begin); add_pbf_error(s, "The format separator does not match", string, begin);
} }
ptr++; ptr++;
} }
@ -2177,9 +2119,9 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
} }
if (*ptr) { if (*ptr) {
if (allow_extra) { if (allow_extra) {
add_pbf_warning(s, TIMELIB_WARN_TRAILING_DATA, "Trailing data", string, ptr); add_pbf_warning(s, "Trailing data", string, ptr);
} else { } else {
add_pbf_error(s, TIMELIB_ERR_TRAILING_DATA, "Trailing data", string, ptr); add_pbf_error(s, "Trailing data", string, ptr);
} }
} }
/* ignore trailing +'s */ /* ignore trailing +'s */
@ -2200,7 +2142,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
break; break;
default: default:
add_pbf_error(s, TIMELIB_ERR_DATA_MISSING, "Data missing", string, ptr); add_pbf_error(s, "Data missing", string, ptr);
done = 1; done = 1;
} }
} }
@ -2223,13 +2165,13 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
if (s->time->h != TIMELIB_UNSET && s->time->i != TIMELIB_UNSET && if (s->time->h != TIMELIB_UNSET && s->time->i != TIMELIB_UNSET &&
s->time->s != TIMELIB_UNSET && s->time->s != TIMELIB_UNSET &&
!timelib_valid_time( s->time->h, s->time->i, s->time->s)) { !timelib_valid_time( s->time->h, s->time->i, s->time->s)) {
add_pbf_warning(s, TIMELIB_WARN_INVALID_TIME, "The parsed time was invalid", string, ptr); add_pbf_warning(s, "The parsed time was invalid", string, ptr);
} }
/* do funky checking whether the parsed date was valid date */ /* do funky checking whether the parsed date was valid date */
if (s->time->y != TIMELIB_UNSET && s->time->m != TIMELIB_UNSET && if (s->time->y != TIMELIB_UNSET && s->time->m != TIMELIB_UNSET &&
s->time->d != TIMELIB_UNSET && s->time->d != TIMELIB_UNSET &&
!timelib_valid_date( s->time->y, s->time->m, s->time->d)) { !timelib_valid_date( s->time->y, s->time->m, s->time->d)) {
add_pbf_warning(s, TIMELIB_WARN_INVALID_DATE, "The parsed date was invalid", string, ptr); add_pbf_warning(s, "The parsed date was invalid", string, ptr);
} }
if (errors) { if (errors) {
@ -2246,22 +2188,15 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options)
parsed->h = 0; parsed->h = 0;
parsed->i = 0; parsed->i = 0;
parsed->s = 0; parsed->s = 0;
parsed->us = 0; parsed->f = 0;
}
if (
parsed->y != TIMELIB_UNSET || parsed->m != TIMELIB_UNSET || parsed->d != TIMELIB_UNSET ||
parsed->h != TIMELIB_UNSET || parsed->i != TIMELIB_UNSET || parsed->s != TIMELIB_UNSET
) {
if (parsed->us == TIMELIB_UNSET) parsed->us = 0;
} else {
if (parsed->us == TIMELIB_UNSET) parsed->us = now->us != TIMELIB_UNSET ? now->us : 0;
} }
if (parsed->y == TIMELIB_UNSET) parsed->y = now->y != TIMELIB_UNSET ? now->y : 0; if (parsed->y == TIMELIB_UNSET) parsed->y = now->y != TIMELIB_UNSET ? now->y : 0;
if (parsed->m == TIMELIB_UNSET) parsed->m = now->m != TIMELIB_UNSET ? now->m : 0;
if (parsed->d == TIMELIB_UNSET) parsed->d = now->d != TIMELIB_UNSET ? now->d : 0; if (parsed->d == TIMELIB_UNSET) parsed->d = now->d != TIMELIB_UNSET ? now->d : 0;
if (parsed->m == TIMELIB_UNSET) parsed->m = now->m != TIMELIB_UNSET ? now->m : 0;
if (parsed->h == TIMELIB_UNSET) parsed->h = now->h != TIMELIB_UNSET ? now->h : 0; if (parsed->h == TIMELIB_UNSET) parsed->h = now->h != TIMELIB_UNSET ? now->h : 0;
if (parsed->i == TIMELIB_UNSET) parsed->i = now->i != TIMELIB_UNSET ? now->i : 0; if (parsed->i == TIMELIB_UNSET) parsed->i = now->i != TIMELIB_UNSET ? now->i : 0;
if (parsed->s == TIMELIB_UNSET) parsed->s = now->s != TIMELIB_UNSET ? now->s : 0; if (parsed->s == TIMELIB_UNSET) parsed->s = now->s != TIMELIB_UNSET ? now->s : 0;
if (parsed->f == TIMELIB_UNSET) parsed->f = now->f != TIMELIB_UNSET ? now->f : 0;
if (parsed->z == TIMELIB_UNSET) parsed->z = now->z != TIMELIB_UNSET ? now->z : 0; if (parsed->z == TIMELIB_UNSET) parsed->z = now->z != TIMELIB_UNSET ? now->z : 0;
if (parsed->dst == TIMELIB_UNSET) parsed->dst = now->dst != TIMELIB_UNSET ? now->dst : 0; if (parsed->dst == TIMELIB_UNSET) parsed->dst = now->dst != TIMELIB_UNSET ? now->dst : 0;

View file

@ -1,4 +1,4 @@
/* Generated by re2c 0.15.3 on Mon Aug 14 13:00:14 2017 */ /* Generated by re2c 0.13.5 on Thu Aug 13 10:30:12 2015 */
#line 1 "ext/date/lib/parse_iso_intervals.re" #line 1 "ext/date/lib/parse_iso_intervals.re"
/* /*
* The MIT License (MIT) * The MIT License (MIT)
@ -27,10 +27,19 @@
/* $Id$ */ /* $Id$ */
#include "timelib.h" #include "timelib.h"
#include "timelib_private.h"
#include <stdio.h>
#include <ctype.h> #include <ctype.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#if defined(_MSC_VER) #if defined(_MSC_VER)
# define strtoll(s, f, b) _atoi64(s) # define strtoll(s, f, b) _atoi64(s)
#elif !defined(HAVE_STRTOLL) #elif !defined(HAVE_STRTOLL)
@ -41,6 +50,15 @@
# endif # endif
#endif #endif
#define TIMELIB_UNSET -99999
#define TIMELIB_SECOND 1
#define TIMELIB_MINUTE 2
#define TIMELIB_HOUR 3
#define TIMELIB_DAY 4
#define TIMELIB_MONTH 5
#define TIMELIB_YEAR 6
#define EOI 257 #define EOI 257
#define TIMELIB_PERIOD 260 #define TIMELIB_PERIOD 260
@ -72,6 +90,8 @@ typedef unsigned char uchar;
#define YYDEBUG(s,c) #define YYDEBUG(s,c)
#endif #endif
#include "timelib_structs.h"
typedef struct Scanner { typedef struct Scanner {
int fd; int fd;
uchar *lim, *str, *ptr, *cur, *tok, *pos; uchar *lim, *str, *ptr, *cur, *tok, *pos;
@ -90,6 +110,15 @@ typedef struct Scanner {
int have_end_date; int have_end_date;
} Scanner; } Scanner;
static void add_warning(Scanner *s, char *error)
{
s->errors->warning_count++;
s->errors->warning_messages = timelib_realloc(s->errors->warning_messages, s->errors->warning_count * sizeof(timelib_error_message));
s->errors->warning_messages[s->errors->warning_count - 1].position = s->tok ? s->tok - s->str : 0;
s->errors->warning_messages[s->errors->warning_count - 1].character = s->tok ? *s->tok : 0;
s->errors->warning_messages[s->errors->warning_count - 1].message = timelib_strdup(error);
}
static void add_error(Scanner *s, char *error) static void add_error(Scanner *s, char *error)
{ {
s->errors->error_count++; s->errors->error_count++;
@ -153,6 +182,55 @@ static timelib_ull timelib_get_unsigned_nr(char **ptr, int max_length)
return dir * timelib_get_nr(ptr, max_length); return dir * timelib_get_nr(ptr, max_length);
} }
static void timelib_eat_spaces(char **ptr)
{
while (**ptr == ' ' || **ptr == '\t') {
++*ptr;
}
}
static void timelib_eat_until_separator(char **ptr)
{
while (strchr(" \t.,:;/-0123456789", **ptr) == NULL) {
++*ptr;
}
}
static timelib_long timelib_get_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb)
{
timelib_long retval = 0;
*tz_not_found = 0;
while (**ptr == ' ' || **ptr == '\t' || **ptr == '(') {
++*ptr;
}
if ((*ptr)[0] == 'G' && (*ptr)[1] == 'M' && (*ptr)[2] == 'T' && ((*ptr)[3] == '+' || (*ptr)[3] == '-')) {
*ptr += 3;
}
if (**ptr == '+') {
++*ptr;
t->is_localtime = 1;
t->zone_type = TIMELIB_ZONETYPE_OFFSET;
*tz_not_found = 0;
t->dst = 0;
retval = -1 * timelib_parse_tz_cor(ptr);
} else if (**ptr == '-') {
++*ptr;
t->is_localtime = 1;
t->zone_type = TIMELIB_ZONETYPE_OFFSET;
*tz_not_found = 0;
t->dst = 0;
retval = timelib_parse_tz_cor(ptr);
}
while (**ptr == ')') {
++*ptr;
}
return retval;
}
#define timelib_split_free(arg) { \ #define timelib_split_free(arg) { \
int i; \ int i; \
for (i = 0; i < arg.c; i++) { \ for (i = 0; i < arg.c; i++) { \
@ -176,49 +254,49 @@ static int scan(Scanner *s)
std: std:
s->tok = cursor; s->tok = cursor;
s->len = 0; s->len = 0;
#line 204 "ext/date/lib/parse_iso_intervals.re" #line 282 "ext/date/lib/parse_iso_intervals.re"
#line 184 "<stdout>" #line 262 "ext/date/lib/parse_iso_intervals.c"
{ {
YYCTYPE yych; YYCTYPE yych;
unsigned int yyaccept = 0; unsigned int yyaccept = 0;
static const unsigned char yybm[] = { static const unsigned char yybm[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 0, 0, 0, 0, 0, 0, 128, 128, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}; };
YYDEBUG(0, *YYCURSOR);
if ((YYLIMIT - YYCURSOR) < 20) YYFILL(20); if ((YYLIMIT - YYCURSOR) < 20) YYFILL(20);
yych = *YYCURSOR; yych = *YYCURSOR;
if (yych <= ',') { if (yych <= ',') {
@ -243,35 +321,30 @@ std:
if (yych != 'R') goto yy11; if (yych != 'R') goto yy11;
} }
} }
YYDEBUG(2, *YYCURSOR);
++YYCURSOR; ++YYCURSOR;
if ((yych = *YYCURSOR) <= '/') goto yy3; if ((yych = *YYCURSOR) <= '/') goto yy3;
if (yych <= '9') goto yy98; if (yych <= '9') goto yy98;
yy3: yy3:
YYDEBUG(3, *YYCURSOR); #line 395 "ext/date/lib/parse_iso_intervals.re"
#line 317 "ext/date/lib/parse_iso_intervals.re"
{ {
add_error(s, "Unexpected character"); add_error(s, "Unexpected character");
goto std; goto std;
} }
#line 258 "<stdout>" #line 334 "ext/date/lib/parse_iso_intervals.c"
yy4: yy4:
YYDEBUG(4, *YYCURSOR);
yyaccept = 0; yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
if (yych <= '/') goto yy3; if (yych <= '/') goto yy3;
if (yych <= '9') goto yy59; if (yych <= '9') goto yy59;
goto yy3; goto yy3;
yy5: yy5:
YYDEBUG(5, *YYCURSOR);
yyaccept = 1; yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
if (yych <= '/') goto yy6; if (yych <= '/') goto yy6;
if (yych <= '9') goto yy12; if (yych <= '9') goto yy12;
if (yych == 'T') goto yy14; if (yych == 'T') goto yy14;
yy6: yy6:
YYDEBUG(6, *YYCURSOR); #line 322 "ext/date/lib/parse_iso_intervals.re"
#line 244 "ext/date/lib/parse_iso_intervals.re"
{ {
timelib_sll nr; timelib_sll nr;
int in_time = 0; int in_time = 0;
@ -312,32 +385,26 @@ yy6:
TIMELIB_DEINIT; TIMELIB_DEINIT;
return TIMELIB_PERIOD; return TIMELIB_PERIOD;
} }
#line 316 "<stdout>" #line 389 "ext/date/lib/parse_iso_intervals.c"
yy7: yy7:
YYDEBUG(7, *YYCURSOR);
++YYCURSOR; ++YYCURSOR;
YYDEBUG(8, *YYCURSOR); #line 384 "ext/date/lib/parse_iso_intervals.re"
#line 306 "ext/date/lib/parse_iso_intervals.re"
{ {
goto std; goto std;
} }
#line 325 "<stdout>" #line 396 "ext/date/lib/parse_iso_intervals.c"
yy9: yy9:
YYDEBUG(9, *YYCURSOR);
++YYCURSOR; ++YYCURSOR;
YYDEBUG(10, *YYCURSOR); #line 389 "ext/date/lib/parse_iso_intervals.re"
#line 311 "ext/date/lib/parse_iso_intervals.re"
{ {
s->pos = cursor; s->line++; s->pos = cursor; s->line++;
goto std; goto std;
} }
#line 335 "<stdout>" #line 404 "ext/date/lib/parse_iso_intervals.c"
yy11: yy11:
YYDEBUG(11, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
goto yy3; goto yy3;
yy12: yy12:
YYDEBUG(12, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= 'L') { if (yych <= 'L') {
if (yych <= '9') { if (yych <= '9') {
@ -354,15 +421,13 @@ yy12:
} }
} }
yy13: yy13:
YYDEBUG(13, *YYCURSOR);
YYCURSOR = YYMARKER; YYCURSOR = YYMARKER;
if (yyaccept == 0) { if (yyaccept <= 0) {
goto yy3; goto yy3;
} else { } else {
goto yy6; goto yy6;
} }
yy14: yy14:
YYDEBUG(14, *YYCURSOR);
yyaccept = 1; yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
if (yybm[0+yych] & 128) { if (yybm[0+yych] & 128) {
@ -370,11 +435,9 @@ yy14:
} }
goto yy6; goto yy6;
yy15: yy15:
YYDEBUG(15, *YYCURSOR);
++YYCURSOR; ++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = *YYCURSOR; yych = *YYCURSOR;
YYDEBUG(16, *YYCURSOR);
if (yybm[0+yych] & 128) { if (yybm[0+yych] & 128) {
goto yy15; goto yy15;
} }
@ -386,28 +449,23 @@ yy15:
if (yych != 'S') goto yy13; if (yych != 'S') goto yy13;
} }
yy17: yy17:
YYDEBUG(17, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
goto yy6; goto yy6;
yy18: yy18:
YYDEBUG(18, *YYCURSOR);
yyaccept = 1; yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
if (yych <= '/') goto yy6; if (yych <= '/') goto yy6;
if (yych <= '9') goto yy22; if (yych <= '9') goto yy22;
goto yy6; goto yy6;
yy19: yy19:
YYDEBUG(19, *YYCURSOR);
yyaccept = 1; yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
if (yych <= '/') goto yy6; if (yych <= '/') goto yy6;
if (yych >= ':') goto yy6; if (yych >= ':') goto yy6;
yy20: yy20:
YYDEBUG(20, *YYCURSOR);
++YYCURSOR; ++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = *YYCURSOR; yych = *YYCURSOR;
YYDEBUG(21, *YYCURSOR);
if (yych <= 'L') { if (yych <= 'L') {
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '9') goto yy20; if (yych <= '9') goto yy20;
@ -418,22 +476,18 @@ yy20:
goto yy13; goto yy13;
} }
yy22: yy22:
YYDEBUG(22, *YYCURSOR);
++YYCURSOR; ++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1); if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = *YYCURSOR; yych = *YYCURSOR;
YYDEBUG(23, *YYCURSOR);
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '9') goto yy22; if (yych <= '9') goto yy22;
if (yych == 'S') goto yy17; if (yych == 'S') goto yy17;
goto yy13; goto yy13;
yy24: yy24:
YYDEBUG(24, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych == 'T') goto yy14; if (yych == 'T') goto yy14;
goto yy6; goto yy6;
yy25: yy25:
YYDEBUG(25, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= 'L') { if (yych <= 'L') {
if (yych <= '9') { if (yych <= '9') {
@ -453,7 +507,6 @@ yy25:
} }
} }
yy26: yy26:
YYDEBUG(26, *YYCURSOR);
yyaccept = 1; yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
if (yych <= '/') goto yy6; if (yych <= '/') goto yy6;
@ -461,7 +514,6 @@ yy26:
if (yych == 'T') goto yy14; if (yych == 'T') goto yy14;
goto yy6; goto yy6;
yy27: yy27:
YYDEBUG(27, *YYCURSOR);
yyaccept = 1; yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
if (yych <= '/') goto yy6; if (yych <= '/') goto yy6;
@ -469,7 +521,6 @@ yy27:
if (yych == 'T') goto yy14; if (yych == 'T') goto yy14;
goto yy6; goto yy6;
yy28: yy28:
YYDEBUG(28, *YYCURSOR);
yyaccept = 1; yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
if (yych <= '/') goto yy6; if (yych <= '/') goto yy6;
@ -477,11 +528,9 @@ yy28:
if (yych == 'T') goto yy14; if (yych == 'T') goto yy14;
goto yy6; goto yy6;
yy29: yy29:
YYDEBUG(29, *YYCURSOR);
++YYCURSOR; ++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = *YYCURSOR; yych = *YYCURSOR;
YYDEBUG(30, *YYCURSOR);
if (yych <= 'D') { if (yych <= 'D') {
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '9') goto yy29; if (yych <= '9') goto yy29;
@ -497,11 +546,9 @@ yy29:
} }
} }
yy31: yy31:
YYDEBUG(31, *YYCURSOR);
++YYCURSOR; ++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = *YYCURSOR; yych = *YYCURSOR;
YYDEBUG(32, *YYCURSOR);
if (yych <= 'C') { if (yych <= 'C') {
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '9') goto yy31; if (yych <= '9') goto yy31;
@ -512,17 +559,14 @@ yy31:
goto yy13; goto yy13;
} }
yy33: yy33:
YYDEBUG(33, *YYCURSOR);
++YYCURSOR; ++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = *YYCURSOR; yych = *YYCURSOR;
YYDEBUG(34, *YYCURSOR);
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '9') goto yy33; if (yych <= '9') goto yy33;
if (yych == 'D') goto yy24; if (yych == 'D') goto yy24;
goto yy13; goto yy13;
yy35: yy35:
YYDEBUG(35, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= 'L') { if (yych <= 'L') {
if (yych <= '9') { if (yych <= '9') {
@ -541,22 +585,18 @@ yy35:
goto yy13; goto yy13;
} }
} }
YYDEBUG(36, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych != '-') goto yy39; if (yych != '-') goto yy39;
YYDEBUG(37, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '0') goto yy40; if (yych <= '0') goto yy40;
if (yych <= '1') goto yy41; if (yych <= '1') goto yy41;
goto yy13; goto yy13;
yy38: yy38:
YYDEBUG(38, *YYCURSOR);
++YYCURSOR; ++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = *YYCURSOR; yych = *YYCURSOR;
yy39: yy39:
YYDEBUG(39, *YYCURSOR);
if (yych <= 'L') { if (yych <= 'L') {
if (yych <= '9') { if (yych <= '9') {
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
@ -576,21 +616,17 @@ yy39:
} }
} }
yy40: yy40:
YYDEBUG(40, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '9') goto yy42; if (yych <= '9') goto yy42;
goto yy13; goto yy13;
yy41: yy41:
YYDEBUG(41, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '3') goto yy13; if (yych >= '3') goto yy13;
yy42: yy42:
YYDEBUG(42, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych != '-') goto yy13; if (yych != '-') goto yy13;
YYDEBUG(43, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '0') goto yy44; if (yych <= '0') goto yy44;
@ -598,70 +634,55 @@ yy42:
if (yych <= '3') goto yy46; if (yych <= '3') goto yy46;
goto yy13; goto yy13;
yy44: yy44:
YYDEBUG(44, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '9') goto yy47; if (yych <= '9') goto yy47;
goto yy13; goto yy13;
yy45: yy45:
YYDEBUG(45, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '9') goto yy47; if (yych <= '9') goto yy47;
goto yy13; goto yy13;
yy46: yy46:
YYDEBUG(46, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '2') goto yy13; if (yych >= '2') goto yy13;
yy47: yy47:
YYDEBUG(47, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych != 'T') goto yy13; if (yych != 'T') goto yy13;
YYDEBUG(48, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '1') goto yy49; if (yych <= '1') goto yy49;
if (yych <= '2') goto yy50; if (yych <= '2') goto yy50;
goto yy13; goto yy13;
yy49: yy49:
YYDEBUG(49, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '9') goto yy51; if (yych <= '9') goto yy51;
goto yy13; goto yy13;
yy50: yy50:
YYDEBUG(50, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '5') goto yy13; if (yych >= '5') goto yy13;
yy51: yy51:
YYDEBUG(51, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych != ':') goto yy13; if (yych != ':') goto yy13;
YYDEBUG(52, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '6') goto yy13; if (yych >= '6') goto yy13;
YYDEBUG(53, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= ':') goto yy13; if (yych >= ':') goto yy13;
YYDEBUG(54, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych != ':') goto yy13; if (yych != ':') goto yy13;
YYDEBUG(55, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '6') goto yy13; if (yych >= '6') goto yy13;
YYDEBUG(56, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= ':') goto yy13; if (yych >= ':') goto yy13;
YYDEBUG(57, *YYCURSOR);
++YYCURSOR; ++YYCURSOR;
YYDEBUG(58, *YYCURSOR); #line 364 "ext/date/lib/parse_iso_intervals.re"
#line 286 "ext/date/lib/parse_iso_intervals.re"
{ {
DEBUG_OUTPUT("combinedrep"); DEBUG_OUTPUT("combinedrep");
TIMELIB_INIT; TIMELIB_INIT;
@ -680,17 +701,14 @@ yy51:
TIMELIB_DEINIT; TIMELIB_DEINIT;
return TIMELIB_PERIOD; return TIMELIB_PERIOD;
} }
#line 684 "<stdout>" #line 705 "ext/date/lib/parse_iso_intervals.c"
yy59: yy59:
YYDEBUG(59, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= ':') goto yy13; if (yych >= ':') goto yy13;
YYDEBUG(60, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= ':') goto yy13; if (yych >= ':') goto yy13;
YYDEBUG(61, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') { if (yych <= '/') {
if (yych == '-') goto yy64; if (yych == '-') goto yy64;
@ -701,40 +719,33 @@ yy59:
goto yy13; goto yy13;
} }
yy62: yy62:
YYDEBUG(62, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '0') goto yy13; if (yych <= '0') goto yy13;
if (yych <= '9') goto yy85; if (yych <= '9') goto yy85;
goto yy13; goto yy13;
yy63: yy63:
YYDEBUG(63, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '2') goto yy85; if (yych <= '2') goto yy85;
goto yy13; goto yy13;
yy64: yy64:
YYDEBUG(64, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '0') goto yy65; if (yych <= '0') goto yy65;
if (yych <= '1') goto yy66; if (yych <= '1') goto yy66;
goto yy13; goto yy13;
yy65: yy65:
YYDEBUG(65, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '0') goto yy13; if (yych <= '0') goto yy13;
if (yych <= '9') goto yy67; if (yych <= '9') goto yy67;
goto yy13; goto yy13;
yy66: yy66:
YYDEBUG(66, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '3') goto yy13; if (yych >= '3') goto yy13;
yy67: yy67:
YYDEBUG(67, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych != '-') goto yy13; if (yych != '-') goto yy13;
YYDEBUG(68, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '0') goto yy69; if (yych <= '0') goto yy69;
@ -742,74 +753,58 @@ yy67:
if (yych <= '3') goto yy71; if (yych <= '3') goto yy71;
goto yy13; goto yy13;
yy69: yy69:
YYDEBUG(69, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '0') goto yy13; if (yych <= '0') goto yy13;
if (yych <= '9') goto yy72; if (yych <= '9') goto yy72;
goto yy13; goto yy13;
yy70: yy70:
YYDEBUG(70, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '9') goto yy72; if (yych <= '9') goto yy72;
goto yy13; goto yy13;
yy71: yy71:
YYDEBUG(71, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '2') goto yy13; if (yych >= '2') goto yy13;
yy72: yy72:
YYDEBUG(72, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych != 'T') goto yy13; if (yych != 'T') goto yy13;
YYDEBUG(73, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '1') goto yy74; if (yych <= '1') goto yy74;
if (yych <= '2') goto yy75; if (yych <= '2') goto yy75;
goto yy13; goto yy13;
yy74: yy74:
YYDEBUG(74, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '9') goto yy76; if (yych <= '9') goto yy76;
goto yy13; goto yy13;
yy75: yy75:
YYDEBUG(75, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '5') goto yy13; if (yych >= '5') goto yy13;
yy76: yy76:
YYDEBUG(76, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych != ':') goto yy13; if (yych != ':') goto yy13;
YYDEBUG(77, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '6') goto yy13; if (yych >= '6') goto yy13;
YYDEBUG(78, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= ':') goto yy13; if (yych >= ':') goto yy13;
YYDEBUG(79, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych != ':') goto yy13; if (yych != ':') goto yy13;
YYDEBUG(80, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '6') goto yy13; if (yych >= '6') goto yy13;
YYDEBUG(81, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= ':') goto yy13; if (yych >= ':') goto yy13;
YYDEBUG(82, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych != 'Z') goto yy13; if (yych != 'Z') goto yy13;
yy83: yy83:
YYDEBUG(83, *YYCURSOR);
++YYCURSOR; ++YYCURSOR;
YYDEBUG(84, *YYCURSOR); #line 298 "ext/date/lib/parse_iso_intervals.re"
#line 220 "ext/date/lib/parse_iso_intervals.re"
{ {
timelib_time *current; timelib_time *current;
@ -832,9 +827,8 @@ yy83:
TIMELIB_DEINIT; TIMELIB_DEINIT;
return TIMELIB_ISO_DATE; return TIMELIB_ISO_DATE;
} }
#line 836 "<stdout>" #line 831 "ext/date/lib/parse_iso_intervals.c"
yy85: yy85:
YYDEBUG(85, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '0') goto yy86; if (yych <= '0') goto yy86;
@ -842,75 +836,60 @@ yy85:
if (yych <= '3') goto yy88; if (yych <= '3') goto yy88;
goto yy13; goto yy13;
yy86: yy86:
YYDEBUG(86, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '0') goto yy13; if (yych <= '0') goto yy13;
if (yych <= '9') goto yy89; if (yych <= '9') goto yy89;
goto yy13; goto yy13;
yy87: yy87:
YYDEBUG(87, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '9') goto yy89; if (yych <= '9') goto yy89;
goto yy13; goto yy13;
yy88: yy88:
YYDEBUG(88, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '2') goto yy13; if (yych >= '2') goto yy13;
yy89: yy89:
YYDEBUG(89, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych != 'T') goto yy13; if (yych != 'T') goto yy13;
YYDEBUG(90, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '1') goto yy91; if (yych <= '1') goto yy91;
if (yych <= '2') goto yy92; if (yych <= '2') goto yy92;
goto yy13; goto yy13;
yy91: yy91:
YYDEBUG(91, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych <= '9') goto yy93; if (yych <= '9') goto yy93;
goto yy13; goto yy13;
yy92: yy92:
YYDEBUG(92, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '5') goto yy13; if (yych >= '5') goto yy13;
yy93: yy93:
YYDEBUG(93, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '6') goto yy13; if (yych >= '6') goto yy13;
YYDEBUG(94, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= ':') goto yy13; if (yych >= ':') goto yy13;
YYDEBUG(95, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= '6') goto yy13; if (yych >= '6') goto yy13;
YYDEBUG(96, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych <= '/') goto yy13; if (yych <= '/') goto yy13;
if (yych >= ':') goto yy13; if (yych >= ':') goto yy13;
YYDEBUG(97, *YYCURSOR);
yych = *++YYCURSOR; yych = *++YYCURSOR;
if (yych == 'Z') goto yy83; if (yych == 'Z') goto yy83;
goto yy13; goto yy13;
yy98: yy98:
YYDEBUG(98, *YYCURSOR);
++YYCURSOR; ++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1); if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = *YYCURSOR; yych = *YYCURSOR;
YYDEBUG(99, *YYCURSOR);
if (yych <= '/') goto yy100; if (yych <= '/') goto yy100;
if (yych <= '9') goto yy98; if (yych <= '9') goto yy98;
yy100: yy100:
YYDEBUG(100, *YYCURSOR); #line 287 "ext/date/lib/parse_iso_intervals.re"
#line 209 "ext/date/lib/parse_iso_intervals.re"
{ {
DEBUG_OUTPUT("recurrences"); DEBUG_OUTPUT("recurrences");
TIMELIB_INIT; TIMELIB_INIT;
@ -920,9 +899,9 @@ yy100:
s->have_recurrences = 1; s->have_recurrences = 1;
return TIMELIB_PERIOD; return TIMELIB_PERIOD;
} }
#line 924 "<stdout>" #line 903 "ext/date/lib/parse_iso_intervals.c"
} }
#line 321 "ext/date/lib/parse_iso_intervals.re" #line 399 "ext/date/lib/parse_iso_intervals.re"
} }
#ifdef PHP_WIN32 #ifdef PHP_WIN32
@ -981,7 +960,7 @@ void timelib_strtointerval(char *s, size_t len,
in.begin->h = TIMELIB_UNSET; in.begin->h = TIMELIB_UNSET;
in.begin->i = TIMELIB_UNSET; in.begin->i = TIMELIB_UNSET;
in.begin->s = TIMELIB_UNSET; in.begin->s = TIMELIB_UNSET;
in.begin->us = 0; in.begin->f = 0;
in.begin->z = 0; in.begin->z = 0;
in.begin->dst = 0; in.begin->dst = 0;
in.begin->is_localtime = 0; in.begin->is_localtime = 0;
@ -994,7 +973,7 @@ void timelib_strtointerval(char *s, size_t len,
in.end->h = TIMELIB_UNSET; in.end->h = TIMELIB_UNSET;
in.end->i = TIMELIB_UNSET; in.end->i = TIMELIB_UNSET;
in.end->s = TIMELIB_UNSET; in.end->s = TIMELIB_UNSET;
in.end->us = 0; in.end->f = 0;
in.end->z = 0; in.end->z = 0;
in.end->dst = 0; in.end->dst = 0;
in.end->is_localtime = 0; in.end->is_localtime = 0;

View file

@ -25,10 +25,19 @@
/* $Id$ */ /* $Id$ */
#include "timelib.h" #include "timelib.h"
#include "timelib_private.h"
#include <stdio.h>
#include <ctype.h> #include <ctype.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#if defined(_MSC_VER) #if defined(_MSC_VER)
# define strtoll(s, f, b) _atoi64(s) # define strtoll(s, f, b) _atoi64(s)
#elif !defined(HAVE_STRTOLL) #elif !defined(HAVE_STRTOLL)
@ -39,6 +48,15 @@
# endif # endif
#endif #endif
#define TIMELIB_UNSET -99999
#define TIMELIB_SECOND 1
#define TIMELIB_MINUTE 2
#define TIMELIB_HOUR 3
#define TIMELIB_DAY 4
#define TIMELIB_MONTH 5
#define TIMELIB_YEAR 6
#define EOI 257 #define EOI 257
#define TIMELIB_PERIOD 260 #define TIMELIB_PERIOD 260
@ -70,6 +88,8 @@ typedef unsigned char uchar;
#define YYDEBUG(s,c) #define YYDEBUG(s,c)
#endif #endif
#include "timelib_structs.h"
typedef struct Scanner { typedef struct Scanner {
int fd; int fd;
uchar *lim, *str, *ptr, *cur, *tok, *pos; uchar *lim, *str, *ptr, *cur, *tok, *pos;
@ -88,6 +108,15 @@ typedef struct Scanner {
int have_end_date; int have_end_date;
} Scanner; } Scanner;
static void add_warning(Scanner *s, char *error)
{
s->errors->warning_count++;
s->errors->warning_messages = timelib_realloc(s->errors->warning_messages, s->errors->warning_count * sizeof(timelib_error_message));
s->errors->warning_messages[s->errors->warning_count - 1].position = s->tok ? s->tok - s->str : 0;
s->errors->warning_messages[s->errors->warning_count - 1].character = s->tok ? *s->tok : 0;
s->errors->warning_messages[s->errors->warning_count - 1].message = timelib_strdup(error);
}
static void add_error(Scanner *s, char *error) static void add_error(Scanner *s, char *error)
{ {
s->errors->error_count++; s->errors->error_count++;
@ -151,6 +180,55 @@ static timelib_ull timelib_get_unsigned_nr(char **ptr, int max_length)
return dir * timelib_get_nr(ptr, max_length); return dir * timelib_get_nr(ptr, max_length);
} }
static void timelib_eat_spaces(char **ptr)
{
while (**ptr == ' ' || **ptr == '\t') {
++*ptr;
}
}
static void timelib_eat_until_separator(char **ptr)
{
while (strchr(" \t.,:;/-0123456789", **ptr) == NULL) {
++*ptr;
}
}
static timelib_long timelib_get_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb)
{
timelib_long retval = 0;
*tz_not_found = 0;
while (**ptr == ' ' || **ptr == '\t' || **ptr == '(') {
++*ptr;
}
if ((*ptr)[0] == 'G' && (*ptr)[1] == 'M' && (*ptr)[2] == 'T' && ((*ptr)[3] == '+' || (*ptr)[3] == '-')) {
*ptr += 3;
}
if (**ptr == '+') {
++*ptr;
t->is_localtime = 1;
t->zone_type = TIMELIB_ZONETYPE_OFFSET;
*tz_not_found = 0;
t->dst = 0;
retval = -1 * timelib_parse_tz_cor(ptr);
} else if (**ptr == '-') {
++*ptr;
t->is_localtime = 1;
t->zone_type = TIMELIB_ZONETYPE_OFFSET;
*tz_not_found = 0;
t->dst = 0;
retval = timelib_parse_tz_cor(ptr);
}
while (**ptr == ')') {
++*ptr;
}
return retval;
}
#define timelib_split_free(arg) { \ #define timelib_split_free(arg) { \
int i; \ int i; \
for (i = 0; i < arg.c; i++) { \ for (i = 0; i < arg.c; i++) { \
@ -376,7 +454,7 @@ void timelib_strtointerval(char *s, size_t len,
in.begin->h = TIMELIB_UNSET; in.begin->h = TIMELIB_UNSET;
in.begin->i = TIMELIB_UNSET; in.begin->i = TIMELIB_UNSET;
in.begin->s = TIMELIB_UNSET; in.begin->s = TIMELIB_UNSET;
in.begin->us = 0; in.begin->f = 0;
in.begin->z = 0; in.begin->z = 0;
in.begin->dst = 0; in.begin->dst = 0;
in.begin->is_localtime = 0; in.begin->is_localtime = 0;
@ -389,7 +467,7 @@ void timelib_strtointerval(char *s, size_t len,
in.end->h = TIMELIB_UNSET; in.end->h = TIMELIB_UNSET;
in.end->i = TIMELIB_UNSET; in.end->i = TIMELIB_UNSET;
in.end->s = TIMELIB_UNSET; in.end->s = TIMELIB_UNSET;
in.end->us = 0; in.end->f = 0;
in.end->z = 0; in.end->z = 0;
in.end->dst = 0; in.end->dst = 0;
in.end->is_localtime = 0; in.end->is_localtime = 0;

View file

@ -23,7 +23,18 @@
*/ */
#include "timelib.h" #include "timelib.h"
#include "timelib_private.h"
#include <stdio.h>
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#define TIMELIB_SUPPORTS_V2DATA #define TIMELIB_SUPPORTS_V2DATA
#include "timezonedb.h" #include "timezonedb.h"
@ -38,32 +49,13 @@
# endif # endif
#endif #endif
#if defined(__s390__)
# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define WORDS_BIGENDIAN
# else
# undef WORDS_BIGENDIAN
# endif
#endif
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
static inline uint32_t timelib_conv_int_unsigned(uint32_t value) #define timelib_conv_int(l) (l)
{
return value;
}
#else #else
static inline uint32_t timelib_conv_int_unsigned(uint32_t value) #define timelib_conv_int(l) ((l & 0x000000ff) << 24) + ((l & 0x0000ff00) << 8) + ((l & 0x00ff0000) >> 8) + ((l & 0xff000000) >> 24)
{
return ((value & 0x000000ff) << 24) +
((value & 0x0000ff00) << 8) +
((value & 0x00ff0000) >> 8) +
((value & 0xff000000) >> 24);
}
#endif #endif
#define timelib_conv_int_signed(value) ((int32_t) timelib_conv_int_unsigned((int32_t) value)) static int read_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
static int read_php_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
{ {
uint32_t version; uint32_t version;
@ -86,67 +78,21 @@ static int read_php_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
return version; return version;
} }
static int read_tzif_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
{
uint32_t version;
/* read ID */
switch ((*tzf)[4]) {
case '\0':
version = 0;
break;
case '2':
version = 2;
break;
case '3':
version = 3;
break;
default:
return -1;
}
*tzf += 5;
/* set BC flag and country code to default */
tz->bc = 0;
tz->location.country_code[0] = '?';
tz->location.country_code[1] = '?';
tz->location.country_code[2] = '\0';
/* skip rest of preamble */
*tzf += 15;
return version;
}
static int read_preamble(const unsigned char **tzf, timelib_tzinfo *tz, unsigned int *type)
{
/* read marker (TZif) or (PHP) */
if (memcmp(*tzf, "PHP", 3) == 0) {
*type = TIMELIB_TZINFO_PHP;
return read_php_preamble(tzf, tz);
} else if (memcmp(*tzf, "TZif", 4) == 0) {
*type = TIMELIB_TZINFO_ZONEINFO;
return read_tzif_preamble(tzf, tz);
} else {
return -1;
}
}
static void read_header(const unsigned char **tzf, timelib_tzinfo *tz) static void read_header(const unsigned char **tzf, timelib_tzinfo *tz)
{ {
uint32_t buffer[6]; uint32_t buffer[6];
memcpy(&buffer, *tzf, sizeof(buffer)); memcpy(&buffer, *tzf, sizeof(buffer));
tz->bit32.ttisgmtcnt = timelib_conv_int_unsigned(buffer[0]); tz->bit32.ttisgmtcnt = timelib_conv_int(buffer[0]);
tz->bit32.ttisstdcnt = timelib_conv_int_unsigned(buffer[1]); tz->bit32.ttisstdcnt = timelib_conv_int(buffer[1]);
tz->bit32.leapcnt = timelib_conv_int_unsigned(buffer[2]); tz->bit32.leapcnt = timelib_conv_int(buffer[2]);
tz->bit32.timecnt = timelib_conv_int_unsigned(buffer[3]); tz->bit32.timecnt = timelib_conv_int(buffer[3]);
tz->bit32.typecnt = timelib_conv_int_unsigned(buffer[4]); tz->bit32.typecnt = timelib_conv_int(buffer[4]);
tz->bit32.charcnt = timelib_conv_int_unsigned(buffer[5]); tz->bit32.charcnt = timelib_conv_int(buffer[5]);
*tzf += sizeof(buffer); *tzf += sizeof(buffer);
} }
static void skip_64bit_transitions(const unsigned char **tzf, timelib_tzinfo *tz) static void skip_64bit_transistions(const unsigned char **tzf, timelib_tzinfo *tz)
{ {
if (tz->bit64.timecnt) { if (tz->bit64.timecnt) {
*tzf += (sizeof(int64_t) * tz->bit64.timecnt); *tzf += (sizeof(int64_t) * tz->bit64.timecnt);
@ -154,7 +100,7 @@ static void skip_64bit_transitions(const unsigned char **tzf, timelib_tzinfo *tz
} }
} }
static int read_transitions(const unsigned char **tzf, timelib_tzinfo *tz) static void read_transistions(const unsigned char **tzf, timelib_tzinfo *tz)
{ {
int32_t *buffer = NULL; int32_t *buffer = NULL;
uint32_t i; uint32_t i;
@ -163,22 +109,18 @@ static int read_transitions(const unsigned char **tzf, timelib_tzinfo *tz)
if (tz->bit32.timecnt) { if (tz->bit32.timecnt) {
buffer = (int32_t*) timelib_malloc(tz->bit32.timecnt * sizeof(int32_t)); buffer = (int32_t*) timelib_malloc(tz->bit32.timecnt * sizeof(int32_t));
if (!buffer) { if (!buffer) {
return TIMELIB_ERROR_CANNOT_ALLOCATE; return;
} }
memcpy(buffer, *tzf, sizeof(int32_t) * tz->bit32.timecnt); memcpy(buffer, *tzf, sizeof(int32_t) * tz->bit32.timecnt);
*tzf += (sizeof(int32_t) * tz->bit32.timecnt); *tzf += (sizeof(int32_t) * tz->bit32.timecnt);
for (i = 0; i < tz->bit32.timecnt; i++) { for (i = 0; i < tz->bit32.timecnt; i++) {
buffer[i] = timelib_conv_int_signed(buffer[i]); buffer[i] = timelib_conv_int(buffer[i]);
/* Sanity check to see whether TS is just increasing */
if (i > 0 && !(buffer[i] > buffer[i - 1])) {
return TIMELIB_ERROR_CORRUPT_TRANSITIONS_DONT_INCREASE;
}
} }
cbuffer = (unsigned char*) timelib_malloc(tz->bit32.timecnt * sizeof(unsigned char)); cbuffer = (unsigned char*) timelib_malloc(tz->bit32.timecnt * sizeof(unsigned char));
if (!cbuffer) { if (!cbuffer) {
timelib_free(buffer); timelib_free(buffer);
return TIMELIB_ERROR_CANNOT_ALLOCATE; return;
} }
memcpy(cbuffer, *tzf, sizeof(unsigned char) * tz->bit32.timecnt); memcpy(cbuffer, *tzf, sizeof(unsigned char) * tz->bit32.timecnt);
*tzf += sizeof(unsigned char) * tz->bit32.timecnt; *tzf += sizeof(unsigned char) * tz->bit32.timecnt;
@ -186,8 +128,6 @@ static int read_transitions(const unsigned char **tzf, timelib_tzinfo *tz)
tz->trans = buffer; tz->trans = buffer;
tz->trans_idx = cbuffer; tz->trans_idx = cbuffer;
return 0;
} }
static void skip_64bit_types(const unsigned char **tzf, timelib_tzinfo *tz) static void skip_64bit_types(const unsigned char **tzf, timelib_tzinfo *tz)
@ -205,7 +145,7 @@ static void skip_64bit_types(const unsigned char **tzf, timelib_tzinfo *tz)
} }
} }
static int read_types(const unsigned char **tzf, timelib_tzinfo *tz) static void read_types(const unsigned char **tzf, timelib_tzinfo *tz)
{ {
unsigned char *buffer; unsigned char *buffer;
int32_t *leap_buffer; int32_t *leap_buffer;
@ -213,7 +153,7 @@ static int read_types(const unsigned char **tzf, timelib_tzinfo *tz)
buffer = (unsigned char*) timelib_malloc(tz->bit32.typecnt * sizeof(unsigned char) * 6); buffer = (unsigned char*) timelib_malloc(tz->bit32.typecnt * sizeof(unsigned char) * 6);
if (!buffer) { if (!buffer) {
return TIMELIB_ERROR_CANNOT_ALLOCATE; return;
} }
memcpy(buffer, *tzf, sizeof(unsigned char) * 6 * tz->bit32.typecnt); memcpy(buffer, *tzf, sizeof(unsigned char) * 6 * tz->bit32.typecnt);
*tzf += sizeof(unsigned char) * 6 * tz->bit32.typecnt; *tzf += sizeof(unsigned char) * 6 * tz->bit32.typecnt;
@ -221,13 +161,12 @@ static int read_types(const unsigned char **tzf, timelib_tzinfo *tz)
tz->type = (ttinfo*) timelib_malloc(tz->bit32.typecnt * sizeof(struct ttinfo)); tz->type = (ttinfo*) timelib_malloc(tz->bit32.typecnt * sizeof(struct ttinfo));
if (!tz->type) { if (!tz->type) {
timelib_free(buffer); timelib_free(buffer);
return TIMELIB_ERROR_CANNOT_ALLOCATE; return;
} }
for (i = 0; i < tz->bit32.typecnt; i++) { for (i = 0; i < tz->bit32.typecnt; i++) {
j = i * 6; j = i * 6;
tz->type[i].offset = 0; tz->type[i].offset = (buffer[j] * 16777216) + (buffer[j + 1] * 65536) + (buffer[j + 2] * 256) + buffer[j + 3];
tz->type[i].offset += (int32_t) (((uint32_t) buffer[j]) << 24) + (buffer[j + 1] << 16) + (buffer[j + 2] << 8) + tz->type[i].offset + buffer[j + 3];
tz->type[i].isdst = buffer[j + 4]; tz->type[i].isdst = buffer[j + 4];
tz->type[i].abbr_idx = buffer[j + 5]; tz->type[i].abbr_idx = buffer[j + 5];
} }
@ -235,7 +174,7 @@ static int read_types(const unsigned char **tzf, timelib_tzinfo *tz)
tz->timezone_abbr = (char*) timelib_malloc(tz->bit32.charcnt); tz->timezone_abbr = (char*) timelib_malloc(tz->bit32.charcnt);
if (!tz->timezone_abbr) { if (!tz->timezone_abbr) {
return TIMELIB_ERROR_CORRUPT_NO_ABBREVIATION; return;
} }
memcpy(tz->timezone_abbr, *tzf, sizeof(char) * tz->bit32.charcnt); memcpy(tz->timezone_abbr, *tzf, sizeof(char) * tz->bit32.charcnt);
*tzf += sizeof(char) * tz->bit32.charcnt; *tzf += sizeof(char) * tz->bit32.charcnt;
@ -243,7 +182,7 @@ static int read_types(const unsigned char **tzf, timelib_tzinfo *tz)
if (tz->bit32.leapcnt) { if (tz->bit32.leapcnt) {
leap_buffer = (int32_t *) timelib_malloc(tz->bit32.leapcnt * 2 * sizeof(int32_t)); leap_buffer = (int32_t *) timelib_malloc(tz->bit32.leapcnt * 2 * sizeof(int32_t));
if (!leap_buffer) { if (!leap_buffer) {
return TIMELIB_ERROR_CANNOT_ALLOCATE; return;
} }
memcpy(leap_buffer, *tzf, sizeof(int32_t) * tz->bit32.leapcnt * 2); memcpy(leap_buffer, *tzf, sizeof(int32_t) * tz->bit32.leapcnt * 2);
*tzf += sizeof(int32_t) * tz->bit32.leapcnt * 2; *tzf += sizeof(int32_t) * tz->bit32.leapcnt * 2;
@ -251,11 +190,11 @@ static int read_types(const unsigned char **tzf, timelib_tzinfo *tz)
tz->leap_times = (tlinfo*) timelib_malloc(tz->bit32.leapcnt * sizeof(tlinfo)); tz->leap_times = (tlinfo*) timelib_malloc(tz->bit32.leapcnt * sizeof(tlinfo));
if (!tz->leap_times) { if (!tz->leap_times) {
timelib_free(leap_buffer); timelib_free(leap_buffer);
return TIMELIB_ERROR_CANNOT_ALLOCATE; return;
} }
for (i = 0; i < tz->bit32.leapcnt; i++) { for (i = 0; i < tz->bit32.leapcnt; i++) {
tz->leap_times[i].trans = timelib_conv_int_signed(leap_buffer[i * 2]); tz->leap_times[i].trans = timelib_conv_int(leap_buffer[i * 2]);
tz->leap_times[i].offset = timelib_conv_int_signed(leap_buffer[i * 2 + 1]); tz->leap_times[i].offset = timelib_conv_int(leap_buffer[i * 2 + 1]);
} }
timelib_free(leap_buffer); timelib_free(leap_buffer);
} }
@ -263,7 +202,7 @@ static int read_types(const unsigned char **tzf, timelib_tzinfo *tz)
if (tz->bit32.ttisstdcnt) { if (tz->bit32.ttisstdcnt) {
buffer = (unsigned char*) timelib_malloc(tz->bit32.ttisstdcnt * sizeof(unsigned char)); buffer = (unsigned char*) timelib_malloc(tz->bit32.ttisstdcnt * sizeof(unsigned char));
if (!buffer) { if (!buffer) {
return TIMELIB_ERROR_CANNOT_ALLOCATE; return;
} }
memcpy(buffer, *tzf, sizeof(unsigned char) * tz->bit32.ttisstdcnt); memcpy(buffer, *tzf, sizeof(unsigned char) * tz->bit32.ttisstdcnt);
*tzf += sizeof(unsigned char) * tz->bit32.ttisstdcnt; *tzf += sizeof(unsigned char) * tz->bit32.ttisstdcnt;
@ -277,7 +216,7 @@ static int read_types(const unsigned char **tzf, timelib_tzinfo *tz)
if (tz->bit32.ttisgmtcnt) { if (tz->bit32.ttisgmtcnt) {
buffer = (unsigned char*) timelib_malloc(tz->bit32.ttisgmtcnt * sizeof(unsigned char)); buffer = (unsigned char*) timelib_malloc(tz->bit32.ttisgmtcnt * sizeof(unsigned char));
if (!buffer) { if (!buffer) {
return TIMELIB_ERROR_CANNOT_ALLOCATE; return;
} }
memcpy(buffer, *tzf, sizeof(unsigned char) * tz->bit32.ttisgmtcnt); memcpy(buffer, *tzf, sizeof(unsigned char) * tz->bit32.ttisgmtcnt);
*tzf += sizeof(unsigned char) * tz->bit32.ttisgmtcnt; *tzf += sizeof(unsigned char) * tz->bit32.ttisgmtcnt;
@ -287,8 +226,6 @@ static int read_types(const unsigned char **tzf, timelib_tzinfo *tz)
} }
timelib_free(buffer); timelib_free(buffer);
} }
return 0;
} }
static void skip_posix_string(const unsigned char **tzf, timelib_tzinfo *tz) static void skip_posix_string(const unsigned char **tzf, timelib_tzinfo *tz)
@ -309,11 +246,11 @@ static void read_location(const unsigned char **tzf, timelib_tzinfo *tz)
uint32_t comments_len; uint32_t comments_len;
memcpy(&buffer, *tzf, sizeof(buffer)); memcpy(&buffer, *tzf, sizeof(buffer));
tz->location.latitude = timelib_conv_int_unsigned(buffer[0]); tz->location.latitude = timelib_conv_int(buffer[0]);
tz->location.latitude = (tz->location.latitude / 100000) - 90; tz->location.latitude = (tz->location.latitude / 100000) - 90;
tz->location.longitude = timelib_conv_int_unsigned(buffer[1]); tz->location.longitude = timelib_conv_int(buffer[1]);
tz->location.longitude = (tz->location.longitude / 100000) - 180; tz->location.longitude = (tz->location.longitude / 100000) - 180;
comments_len = timelib_conv_int_unsigned(buffer[2]); comments_len = timelib_conv_int(buffer[2]);
*tzf += sizeof(buffer); *tzf += sizeof(buffer);
tz->location.comments = timelib_malloc(comments_len + 1); tz->location.comments = timelib_malloc(comments_len + 1);
@ -322,15 +259,6 @@ static void read_location(const unsigned char **tzf, timelib_tzinfo *tz)
*tzf += comments_len; *tzf += comments_len;
} }
static void set_default_location_and_comments(const unsigned char **tzf, timelib_tzinfo *tz)
{
tz->location.latitude = 0;
tz->location.longitude = 0;
tz->location.comments = timelib_malloc(2);
tz->location.comments[0] = '?';
tz->location.comments[1] = '\0';
}
void timelib_dump_tzinfo(timelib_tzinfo *tz) void timelib_dump_tzinfo(timelib_tzinfo *tz)
{ {
uint32_t i; uint32_t i;
@ -379,13 +307,7 @@ static int seek_to_tz_position(const unsigned char **tzf, char *timezone, const
int left = 0, right = tzdb->index_size - 1; int left = 0, right = tzdb->index_size - 1;
#ifdef HAVE_SETLOCALE #ifdef HAVE_SETLOCALE
char *cur_locale = NULL, *tmp; char *cur_locale = NULL, *tmp;
#endif
if (tzdb->index_size == 0) {
return 0;
}
#ifdef HAVE_SETLOCALE
tmp = setlocale(LC_CTYPE, NULL); tmp = setlocale(LC_CTYPE, NULL);
if (tmp) { if (tmp) {
cur_locale = timelib_strdup(tmp); cur_locale = timelib_strdup(tmp);
@ -424,10 +346,10 @@ const timelib_tzdb *timelib_builtin_db(void)
return &timezonedb_builtin; return &timezonedb_builtin;
} }
const timelib_tzdb_index_entry *timelib_timezone_identifiers_list(timelib_tzdb *tzdb, int *count) const timelib_tzdb_index_entry *timelib_timezone_builtin_identifiers_list(int *count)
{ {
*count = tzdb->index_size; *count = sizeof(timezonedb_idx_builtin) / sizeof(*timezonedb_idx_builtin);
return tzdb->index; return timezonedb_idx_builtin;
} }
int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb) int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb)
@ -436,17 +358,9 @@ int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb)
return (seek_to_tz_position(&tzf, timezone, tzdb)); return (seek_to_tz_position(&tzf, timezone, tzdb));
} }
static int skip_64bit_preamble(const unsigned char **tzf, timelib_tzinfo *tz) static void skip_64bit_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
{ {
if (memcmp(*tzf, "TZif2", 5) == 0) { *tzf += 20;
*tzf += 20;
return 1;
} else if (memcmp(*tzf, "TZif3", 5) == 0) {
*tzf += 20;
return 1;
} else {
return 0;
}
} }
static void read_64bit_header(const unsigned char **tzf, timelib_tzinfo *tz) static void read_64bit_header(const unsigned char **tzf, timelib_tzinfo *tz)
@ -454,124 +368,43 @@ static void read_64bit_header(const unsigned char **tzf, timelib_tzinfo *tz)
uint32_t buffer[6]; uint32_t buffer[6];
memcpy(&buffer, *tzf, sizeof(buffer)); memcpy(&buffer, *tzf, sizeof(buffer));
tz->bit64.ttisgmtcnt = timelib_conv_int_unsigned(buffer[0]); tz->bit64.ttisgmtcnt = timelib_conv_int(buffer[0]);
tz->bit64.ttisstdcnt = timelib_conv_int_unsigned(buffer[1]); tz->bit64.ttisstdcnt = timelib_conv_int(buffer[1]);
tz->bit64.leapcnt = timelib_conv_int_unsigned(buffer[2]); tz->bit64.leapcnt = timelib_conv_int(buffer[2]);
tz->bit64.timecnt = timelib_conv_int_unsigned(buffer[3]); tz->bit64.timecnt = timelib_conv_int(buffer[3]);
tz->bit64.typecnt = timelib_conv_int_unsigned(buffer[4]); tz->bit64.typecnt = timelib_conv_int(buffer[4]);
tz->bit64.charcnt = timelib_conv_int_unsigned(buffer[5]); tz->bit64.charcnt = timelib_conv_int(buffer[5]);
*tzf += sizeof(buffer); *tzf += sizeof(buffer);
} }
static timelib_tzinfo* timelib_tzinfo_ctor(char *name) timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb)
{
timelib_tzinfo *t;
t = timelib_calloc(1, sizeof(timelib_tzinfo));
t->name = timelib_strdup(name);
return t;
}
timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb, int *error_code)
{ {
const unsigned char *tzf; const unsigned char *tzf;
timelib_tzinfo *tmp; timelib_tzinfo *tmp;
int version; int version;
int transitions_result, types_result;
unsigned int type; /* TIMELIB_TZINFO_PHP or TIMELIB_TZINFO_ZONEINFO */
if (seek_to_tz_position(&tzf, timezone, tzdb)) { if (seek_to_tz_position(&tzf, timezone, tzdb)) {
tmp = timelib_tzinfo_ctor(timezone); tmp = timelib_tzinfo_ctor(timezone);
version = read_preamble(&tzf, tmp, &type); version = read_preamble(&tzf, tmp);
if (version == -1) {
*error_code = TIMELIB_ERROR_UNSUPPORTED_VERSION;
timelib_tzinfo_dtor(tmp);
return NULL;
}
//printf("- timezone: %s, version: %0d\n", timezone, version);
read_header(&tzf, tmp); read_header(&tzf, tmp);
if ((transitions_result = read_transitions(&tzf, tmp)) != 0) { read_transistions(&tzf, tmp);
/* Corrupt file as transitions do not increase */ read_types(&tzf, tmp);
*error_code = transitions_result; if (version == 2) {
timelib_tzinfo_dtor(tmp); skip_64bit_preamble(&tzf, tmp);
return NULL;
}
if ((types_result = read_types(&tzf, tmp)) != 0) {
*error_code = types_result;
timelib_tzinfo_dtor(tmp);
return NULL;
}
if (version == 2 || version == 3) {
if (!skip_64bit_preamble(&tzf, tmp)) {
/* 64 bit preamble is not in place */
*error_code = TIMELIB_ERROR_CORRUPT_NO_64BIT_PREAMBLE;
return NULL;
}
read_64bit_header(&tzf, tmp); read_64bit_header(&tzf, tmp);
skip_64bit_transitions(&tzf, tmp); skip_64bit_transistions(&tzf, tmp);
skip_64bit_types(&tzf, tmp); skip_64bit_types(&tzf, tmp);
skip_posix_string(&tzf, tmp); skip_posix_string(&tzf, tmp);
} }
read_location(&tzf, tmp);
if (type == TIMELIB_TZINFO_PHP) {
read_location(&tzf, tmp);
} else {
set_default_location_and_comments(&tzf, tmp);
}
} else { } else {
*error_code = TIMELIB_ERROR_NO_SUCH_TIMEZONE;
tmp = NULL; tmp = NULL;
} }
return tmp; return tmp;
} }
void timelib_tzinfo_dtor(timelib_tzinfo *tz)
{
TIMELIB_TIME_FREE(tz->name);
TIMELIB_TIME_FREE(tz->trans);
TIMELIB_TIME_FREE(tz->trans_idx);
TIMELIB_TIME_FREE(tz->type);
TIMELIB_TIME_FREE(tz->timezone_abbr);
TIMELIB_TIME_FREE(tz->leap_times);
TIMELIB_TIME_FREE(tz->location.comments);
TIMELIB_TIME_FREE(tz);
tz = NULL;
}
timelib_tzinfo *timelib_tzinfo_clone(timelib_tzinfo *tz)
{
timelib_tzinfo *tmp = timelib_tzinfo_ctor(tz->name);
tmp->bit32.ttisgmtcnt = tz->bit32.ttisgmtcnt;
tmp->bit32.ttisstdcnt = tz->bit32.ttisstdcnt;
tmp->bit32.leapcnt = tz->bit32.leapcnt;
tmp->bit32.timecnt = tz->bit32.timecnt;
tmp->bit32.typecnt = tz->bit32.typecnt;
tmp->bit32.charcnt = tz->bit32.charcnt;
if (tz->bit32.timecnt) {
tmp->trans = (int32_t *) timelib_malloc(tz->bit32.timecnt * sizeof(int32_t));
tmp->trans_idx = (unsigned char*) timelib_malloc(tz->bit32.timecnt * sizeof(unsigned char));
memcpy(tmp->trans, tz->trans, tz->bit32.timecnt * sizeof(int32_t));
memcpy(tmp->trans_idx, tz->trans_idx, tz->bit32.timecnt * sizeof(unsigned char));
}
tmp->type = (ttinfo*) timelib_malloc(tz->bit32.typecnt * sizeof(struct ttinfo));
memcpy(tmp->type, tz->type, tz->bit32.typecnt * sizeof(struct ttinfo));
tmp->timezone_abbr = (char*) timelib_malloc(tz->bit32.charcnt);
memcpy(tmp->timezone_abbr, tz->timezone_abbr, tz->bit32.charcnt);
if (tz->bit32.leapcnt) {
tmp->leap_times = (tlinfo*) timelib_malloc(tz->bit32.leapcnt * sizeof(tlinfo));
memcpy(tmp->leap_times, tz->leap_times, tz->bit32.leapcnt * sizeof(tlinfo));
}
return tmp;
}
static ttinfo* fetch_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib_sll *transition_time) static ttinfo* fetch_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib_sll *transition_time)
{ {
uint32_t i; uint32_t i;
@ -650,18 +483,18 @@ timelib_time_offset *timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *
int32_t offset = 0, leap_secs = 0; int32_t offset = 0, leap_secs = 0;
char *abbr; char *abbr;
timelib_time_offset *tmp = timelib_time_offset_ctor(); timelib_time_offset *tmp = timelib_time_offset_ctor();
timelib_sll transition_time; timelib_sll transistion_time;
if ((to = fetch_timezone_offset(tz, ts, &transition_time))) { if ((to = fetch_timezone_offset(tz, ts, &transistion_time))) {
offset = to->offset; offset = to->offset;
abbr = &(tz->timezone_abbr[to->abbr_idx]); abbr = &(tz->timezone_abbr[to->abbr_idx]);
tmp->is_dst = to->isdst; tmp->is_dst = to->isdst;
tmp->transition_time = transition_time; tmp->transistion_time = transistion_time;
} else { } else {
offset = 0; offset = 0;
abbr = tz->timezone_abbr; abbr = tz->timezone_abbr;
tmp->is_dst = 0; tmp->is_dst = 0;
tmp->transition_time = 0; tmp->transistion_time = 0;
} }
if ((tl = fetch_leaptime_offset(tz, ts))) { if ((tl = fetch_leaptime_offset(tz, ts))) {
@ -683,7 +516,7 @@ timelib_sll timelib_get_current_offset(timelib_time *t)
switch (t->zone_type) { switch (t->zone_type) {
case TIMELIB_ZONETYPE_ABBR: case TIMELIB_ZONETYPE_ABBR:
case TIMELIB_ZONETYPE_OFFSET: case TIMELIB_ZONETYPE_OFFSET:
return t->z + (t->dst * 3600); return (t->z + t->dst) * -60;
case TIMELIB_ZONETYPE_ID: case TIMELIB_ZONETYPE_ID:
gmt_offset = timelib_get_time_zone_info(t->sse, t->tz_info); gmt_offset = timelib_get_time_zone_info(t->sse, t->tz_info);

View file

@ -23,31 +23,18 @@
*/ */
#include "timelib.h" #include "timelib.h"
#include "timelib_private.h"
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
#define TIMELIB_TIME_FREE(m) \
if (m) { \
timelib_free(m); \
m = NULL; \
} \
#define TIMELIB_LLABS(y) (y < 0 ? (y * -1) : y) #define TIMELIB_LLABS(y) (y < 0 ? (y * -1) : y)
const char *timelib_error_messages[8] = { #define HOUR(a) (int)(a * 60)
"No error",
"Can not allocate buffer for parsing",
"Corrupt tzfile: The transitions in the file don't always increase",
"Corrupt tzfile: The expected 64-bit preamble is missing",
"Corrupt tzfile: No abbreviation could be found for a transition",
"The version used in this timezone identifier is unsupported",
"No timezone with this name could be found",
};
const char *timelib_get_error_message(int error_code)
{
int entries = sizeof(timelib_error_messages) / sizeof(char*);
if (error_code >= 0 && error_code < entries) {
return timelib_error_messages[error_code];
}
return "Unknown error code";
}
timelib_time* timelib_time_ctor(void) timelib_time* timelib_time_ctor(void)
{ {
@ -57,23 +44,12 @@ timelib_time* timelib_time_ctor(void)
return t; return t;
} }
void timelib_time_dtor(timelib_time* t) timelib_rel_time* timelib_rel_time_ctor(void)
{ {
TIMELIB_TIME_FREE(t->tz_abbr); timelib_rel_time *t;
TIMELIB_TIME_FREE(t); t = timelib_calloc(1, sizeof(timelib_rel_time));
}
int timelib_time_compare(timelib_time *t1, timelib_time *t2) return t;
{
if (t1->sse == t2->sse) {
if (t1->us == t2->us) {
return 0;
}
return (t1->us < t2->us) ? -1 : 1;
}
return (t1->sse < t2->sse) ? -1 : 1;
} }
timelib_time* timelib_time_clone(timelib_time *orig) timelib_time* timelib_time_clone(timelib_time *orig)
@ -89,17 +65,21 @@ timelib_time* timelib_time_clone(timelib_time *orig)
return tmp; return tmp;
} }
timelib_rel_time* timelib_rel_time_ctor(void) int timelib_time_compare(timelib_time *t1, timelib_time *t2)
{ {
timelib_rel_time *t; if (t1->sse == t2->sse) {
t = timelib_calloc(1, sizeof(timelib_rel_time)); if (t1->f == t2->f) {
return 0;
}
return t; if (t1->sse < 0) {
} return (t1->f < t2->f) ? 1 : -1;
} else {
return (t1->f < t2->f) ? -1 : 1;
}
}
void timelib_rel_time_dtor(timelib_rel_time* t) return (t1->sse < t2->sse) ? -1 : 1;
{
TIMELIB_TIME_FREE(t);
} }
timelib_rel_time* timelib_rel_time_clone(timelib_rel_time *rel) timelib_rel_time* timelib_rel_time_clone(timelib_rel_time *rel)
@ -121,6 +101,17 @@ void timelib_time_tz_abbr_update(timelib_time* tm, char* tz_abbr)
} }
} }
void timelib_time_dtor(timelib_time* t)
{
TIMELIB_TIME_FREE(t->tz_abbr);
TIMELIB_TIME_FREE(t);
}
void timelib_rel_time_dtor(timelib_rel_time* t)
{
TIMELIB_TIME_FREE(t);
}
timelib_time_offset* timelib_time_offset_ctor(void) timelib_time_offset* timelib_time_offset_ctor(void)
{ {
timelib_time_offset *t; timelib_time_offset *t;
@ -135,6 +126,55 @@ void timelib_time_offset_dtor(timelib_time_offset* t)
TIMELIB_TIME_FREE(t); TIMELIB_TIME_FREE(t);
} }
timelib_tzinfo* timelib_tzinfo_ctor(char *name)
{
timelib_tzinfo *t;
t = timelib_calloc(1, sizeof(timelib_tzinfo));
t->name = timelib_strdup(name);
return t;
}
timelib_tzinfo *timelib_tzinfo_clone(timelib_tzinfo *tz)
{
timelib_tzinfo *tmp = timelib_tzinfo_ctor(tz->name);
tmp->bit32.ttisgmtcnt = tz->bit32.ttisgmtcnt;
tmp->bit32.ttisstdcnt = tz->bit32.ttisstdcnt;
tmp->bit32.leapcnt = tz->bit32.leapcnt;
tmp->bit32.timecnt = tz->bit32.timecnt;
tmp->bit32.typecnt = tz->bit32.typecnt;
tmp->bit32.charcnt = tz->bit32.charcnt;
tmp->trans = (int32_t *) timelib_malloc(tz->bit32.timecnt * sizeof(int32_t));
tmp->trans_idx = (unsigned char*) timelib_malloc(tz->bit32.timecnt * sizeof(unsigned char));
memcpy(tmp->trans, tz->trans, tz->bit32.timecnt * sizeof(int32_t));
memcpy(tmp->trans_idx, tz->trans_idx, tz->bit32.timecnt * sizeof(unsigned char));
tmp->type = (ttinfo*) timelib_malloc(tz->bit32.typecnt * sizeof(struct ttinfo));
memcpy(tmp->type, tz->type, tz->bit32.typecnt * sizeof(struct ttinfo));
tmp->timezone_abbr = (char*) timelib_malloc(tz->bit32.charcnt);
memcpy(tmp->timezone_abbr, tz->timezone_abbr, tz->bit32.charcnt);
tmp->leap_times = (tlinfo*) timelib_malloc(tz->bit32.leapcnt * sizeof(tlinfo));
memcpy(tmp->leap_times, tz->leap_times, tz->bit32.leapcnt * sizeof(tlinfo));
return tmp;
}
void timelib_tzinfo_dtor(timelib_tzinfo *tz)
{
TIMELIB_TIME_FREE(tz->name);
TIMELIB_TIME_FREE(tz->trans);
TIMELIB_TIME_FREE(tz->trans_idx);
TIMELIB_TIME_FREE(tz->type);
TIMELIB_TIME_FREE(tz->timezone_abbr);
TIMELIB_TIME_FREE(tz->leap_times);
TIMELIB_TIME_FREE(tz->location.comments);
TIMELIB_TIME_FREE(tz);
tz = NULL;
}
char *timelib_get_tz_abbr_ptr(timelib_time *t) char *timelib_get_tz_abbr_ptr(timelib_time *t)
{ {
if (!t->sse_uptodate) { if (!t->sse_uptodate) {
@ -178,24 +218,9 @@ timelib_long timelib_date_to_int(timelib_time *d, int *error)
void timelib_decimal_hour_to_hms(double h, int *hour, int *min, int *sec) void timelib_decimal_hour_to_hms(double h, int *hour, int *min, int *sec)
{ {
if (h > 0) { *hour = floor(h);
*hour = floor(h); *min = floor((h - *hour) * 60);
*min = floor((h - *hour) * 60); *sec = (h - *hour - ((float) *min / 60)) * 3600;
*sec = (h - *hour - ((float) *min / 60)) * 3600;
} else {
*hour = ceil(h);
*min = 0 - ceil((h - *hour) * 60);
*sec = 0 - (h - *hour - ((float) *min / -60)) * 3600;
}
}
void timelib_hms_to_decimal_hour(int hour, int min, int sec, double *h)
{
if (hour > 0) {
*h = ((double)hour + (double)min / 60 + (double)sec / 3600);
} else {
*h = ((double)hour - (double)min / 60 - (double)sec / 3600);
}
} }
void timelib_dump_date(timelib_time *d, int options) void timelib_dump_date(timelib_time *d, int options)
@ -205,8 +230,8 @@ void timelib_dump_date(timelib_time *d, int options)
} }
printf("TS: %lld | %s%04lld-%02lld-%02lld %02lld:%02lld:%02lld", printf("TS: %lld | %s%04lld-%02lld-%02lld %02lld:%02lld:%02lld",
d->sse, d->y < 0 ? "-" : "", TIMELIB_LLABS(d->y), d->m, d->d, d->h, d->i, d->s); d->sse, d->y < 0 ? "-" : "", TIMELIB_LLABS(d->y), d->m, d->d, d->h, d->i, d->s);
if (d->us > 0) { if (d->f > +0.0) {
printf(" 0.%06lld", d->us); printf(" %.5f", d->f);
} }
if (d->is_localtime) { if (d->is_localtime) {
@ -235,9 +260,6 @@ void timelib_dump_date(timelib_time *d, int options)
if (d->have_relative) { if (d->have_relative) {
printf("%3lldY %3lldM %3lldD / %3lldH %3lldM %3lldS", printf("%3lldY %3lldM %3lldD / %3lldH %3lldM %3lldS",
d->relative.y, d->relative.m, d->relative.d, d->relative.h, d->relative.i, d->relative.s); d->relative.y, d->relative.m, d->relative.d, d->relative.h, d->relative.i, d->relative.s);
if (d->relative.us) {
printf(" 0.%06lld", d->relative.us);
}
if (d->relative.first_last_day_of != 0) { if (d->relative.first_last_day_of != 0) {
switch (d->relative.first_last_day_of) { switch (d->relative.first_last_day_of) {
case 1: case 1:
@ -285,3 +307,36 @@ void timelib_dump_rel_time(timelib_rel_time *d)
} }
printf("\n"); printf("\n");
} }
timelib_long timelib_parse_tz_cor(char **ptr)
{
char *begin = *ptr, *end;
timelib_long tmp;
while (isdigit(**ptr) || **ptr == ':') {
++*ptr;
}
end = *ptr;
switch (end - begin) {
case 1: /* H */
case 2: /* HH */
return HOUR(strtol(begin, NULL, 10));
break;
case 3: /* H:M */
case 4: /* H:MM, HH:M, HHMM */
if (begin[1] == ':') {
tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 2, NULL, 10);
return tmp;
} else if (begin[2] == ':') {
tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);
return tmp;
} else {
tmp = strtol(begin, NULL, 10);
return HOUR(tmp / 100) + tmp % 100;
}
case 5: /* HH:MM */
tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);
return tmp;
}
return 0;
}

View file

@ -25,283 +25,11 @@
#ifndef __TIMELIB_H__ #ifndef __TIMELIB_H__
#define __TIMELIB_H__ #define __TIMELIB_H__
#ifdef HAVE_TIMELIB_CONFIG_H #include "timelib_structs.h"
# include "timelib_config.h" #if HAVE_LIMITS_H
#endif
#include <stdlib.h>
#include <limits.h> #include <limits.h>
#include <inttypes.h>
# ifndef HAVE_INT32_T
# if SIZEOF_INT == 4
typedef int int32_t;
# elif SIZEOF_LONG == 4
typedef long int int32_t;
# endif
# endif
# ifndef HAVE_UINT32_T
# if SIZEOF_INT == 4
typedef unsigned int uint32_t;
# elif SIZEOF_LONG == 4
typedef unsigned long int uint32_t;
# endif
# endif
#ifdef _WIN32
# if _MSC_VER >= 1600
# include <stdint.h>
# endif
# ifndef SIZEOF_INT
# define SIZEOF_INT 4
# endif
# ifndef SIZEOF_LONG
# define SIZEOF_LONG 4
# endif
# ifndef int32_t
typedef __int32 int32_t;
# endif
# ifndef uint32_t
typedef unsigned __int32 uint32_t;
# endif
# ifndef int64_t
typedef __int64 int64_t;
# endif
# ifndef uint64_t
typedef unsigned __int64 uint64_t;
# endif
# ifndef PRId32
# define PRId32 "I32d"
# endif
# ifndef PRIu32
# define PRIu32 "I32u"
# endif
# ifndef PRId64
# define PRId64 "I64d"
# endif
# ifndef PRIu64
# define PRIu64 "I64u"
# endif
# ifndef INT32_MAX
#define INT32_MAX _I32_MAX
# endif
# ifndef INT32_MIN
#define INT32_MIN ((int32_t)_I32_MIN)
# endif
# ifndef UINT32_MAX
#define UINT32_MAX _UI32_MAX
# endif
# ifndef INT64_MIN
#define INT64_MIN ((int64_t)_I64_MIN)
# endif
# ifndef INT64_MAX
#define INT64_MAX _I64_MAX
# endif
# ifndef UINT64_MAX
#define UINT64_MAX _UI64_MAX
# endif
#endif #endif
#if (defined(__x86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)) && !defined(TIMELIB_FORCE_LONG32)
typedef int64_t timelib_long;
typedef uint64_t timelib_ulong;
# define TIMELIB_LONG_MAX INT64_MAX
# define TIMELIB_LONG_MIN INT64_MIN
# define TIMELIB_ULONG_MAX UINT64_MAX
# define TIMELIB_LONG_FMT "%" PRId64
# define TIMELIB_ULONG_FMT "%" PRIu64
#else
typedef int32_t timelib_long;
typedef uint32_t timelib_ulong;
# define TIMELIB_LONG_MAX INT32_MAX
# define TIMELIB_LONG_MIN INT32_MIN
# define TIMELIB_ULONG_MAX UINT32_MAX
# define TIMELIB_LONG_FMT "%" PRId32
# define TIMELIB_ULONG_FMT "%" PRIu32
#endif
#if defined(_MSC_VER)
typedef uint64_t timelib_ull;
typedef int64_t timelib_sll;
# define TIMELIB_LL_CONST(n) n ## i64
#else
typedef unsigned long long timelib_ull;
typedef signed long long timelib_sll;
# define TIMELIB_LL_CONST(n) n ## ll
#endif
typedef struct ttinfo ttinfo;
typedef struct tlinfo tlinfo;
typedef struct tlocinfo
{
char country_code[3];
double latitude;
double longitude;
char *comments;
} tlocinfo;
typedef struct timelib_tzinfo
{
char *name;
struct {
uint32_t ttisgmtcnt;
uint32_t ttisstdcnt;
uint32_t leapcnt;
uint32_t timecnt;
uint32_t typecnt;
uint32_t charcnt;
} bit32;
struct {
uint64_t ttisgmtcnt;
uint64_t ttisstdcnt;
uint64_t leapcnt;
uint64_t timecnt;
uint64_t typecnt;
uint64_t charcnt;
} bit64;
int32_t *trans;
unsigned char *trans_idx;
ttinfo *type;
char *timezone_abbr;
tlinfo *leap_times;
unsigned char bc;
tlocinfo location;
} timelib_tzinfo;
typedef struct timelib_rel_time {
timelib_sll y, m, d; /* Years, Months and Days */
timelib_sll h, i, s; /* Hours, mInutes and Seconds */
timelib_sll us; /* Microseconds */
int weekday; /* Stores the day in 'next monday' */
int weekday_behavior; /* 0: the current day should *not* be counted when advancing forwards; 1: the current day *should* be counted */
int first_last_day_of;
int invert; /* Whether the difference should be inverted */
timelib_sll days; /* Contains the number of *days*, instead of Y-M-D differences */
struct {
unsigned int type;
timelib_sll amount;
} special;
unsigned int have_weekday_relative, have_special_relative;
} timelib_rel_time;
typedef struct timelib_time_offset {
int32_t offset;
unsigned int leap_secs;
unsigned int is_dst;
char *abbr;
timelib_sll transition_time;
} timelib_time_offset;
typedef struct timelib_time {
timelib_sll y, m, d; /* Year, Month, Day */
timelib_sll h, i, s; /* Hour, mInute, Second */
timelib_sll us; /* Microseconds */
int z; /* UTC offset in seconds */
char *tz_abbr; /* Timezone abbreviation (display only) */
timelib_tzinfo *tz_info; /* Timezone structure */
signed int dst; /* Flag if we were parsing a DST zone */
timelib_rel_time relative;
timelib_sll sse; /* Seconds since epoch */
unsigned int have_time, have_date, have_zone, have_relative, have_weeknr_day;
unsigned int sse_uptodate; /* !0 if the sse member is up to date with the date/time members */
unsigned int tim_uptodate; /* !0 if the date/time members are up to date with the sse member */
unsigned int is_localtime; /* 1 if the current struct represents localtime, 0 if it is in GMT */
unsigned int zone_type; /* 1 time offset,
* 3 TimeZone identifier,
* 2 TimeZone abbreviation */
} timelib_time;
typedef struct timelib_abbr_info {
timelib_sll utc_offset;
char *abbr;
int dst;
} timelib_abbr_info;
#define TIMELIB_WARN_MASK 0x1ff
#define TIMELIB_ERR_MASK 0x2ff
#define TIMELIB_WARN_DOUBLE_TZ 0x101
#define TIMELIB_WARN_INVALID_TIME 0x102
#define TIMELIB_WARN_INVALID_DATE 0x103
#define TIMELIB_WARN_TRAILING_DATA 0x11a
#define TIMELIB_ERR_DOUBLE_TZ 0x201
#define TIMELIB_ERR_TZID_NOT_FOUND 0x202
#define TIMELIB_ERR_DOUBLE_TIME 0x203
#define TIMELIB_ERR_DOUBLE_DATE 0x204
#define TIMELIB_ERR_UNEXPECTED_CHARACTER 0x205
#define TIMELIB_ERR_EMPTY_STRING 0x206
#define TIMELIB_ERR_UNEXPECTED_DATA 0x207
#define TIMELIB_ERR_NO_TEXTUAL_DAY 0x208
#define TIMELIB_ERR_NO_TWO_DIGIT_DAY 0x209
#define TIMELIB_ERR_NO_THREE_DIGIT_DAY_OF_YEAR 0x20a
#define TIMELIB_ERR_NO_TWO_DIGIT_MONTH 0x20b
#define TIMELIB_ERR_NO_TEXTUAL_MONTH 0x20c
#define TIMELIB_ERR_NO_TWO_DIGIT_YEAR 0x20d
#define TIMELIB_ERR_NO_FOUR_DIGIT_YEAR 0x20e
#define TIMELIB_ERR_NO_TWO_DIGIT_HOUR 0x20f
#define TIMELIB_ERR_HOUR_LARGER_THAN_12 0x210
#define TIMELIB_ERR_MERIDIAN_BEFORE_HOUR 0x211
#define TIMELIB_ERR_NO_MERIDIAN 0x212
#define TIMELIB_ERR_NO_TWO_DIGIT_MINUTE 0x213
#define TIMELIB_ERR_NO_TWO_DIGIT_SECOND 0x214
#define TIMELIB_ERR_NO_SIX_DIGIT_MICROSECOND 0x215
#define TIMELIB_ERR_NO_SEP_SYMBOL 0x216
#define TIMELIB_ERR_EXPECTED_ESCAPE_CHAR 0x217
#define TIMELIB_ERR_NO_ESCAPED_CHAR 0x218
#define TIMELIB_ERR_WRONG_FORMAT_SEP 0x219
#define TIMELIB_ERR_TRAILING_DATA 0x21a
#define TIMELIB_ERR_DATA_MISSING 0x21b
#define TIMELIB_ZONETYPE_OFFSET 1
#define TIMELIB_ZONETYPE_ABBR 2
#define TIMELIB_ZONETYPE_ID 3
typedef struct timelib_error_message {
int error_code;
int position;
char character;
char *message;
} timelib_error_message;
typedef struct timelib_error_container {
struct timelib_error_message *error_messages;
struct timelib_error_message *warning_messages;
int error_count;
int warning_count;
} timelib_error_container;
typedef struct _timelib_tz_lookup_table {
char *name;
int type;
float gmtoffset;
char *full_tz_name;
} timelib_tz_lookup_table;
typedef struct _timelib_tzdb_index_entry {
char *id;
unsigned int pos;
} timelib_tzdb_index_entry;
typedef struct _timelib_tzdb {
char *version;
int index_size;
const timelib_tzdb_index_entry *index;
const unsigned char *data;
} timelib_tzdb;
#ifndef timelib_malloc #ifndef timelib_malloc
# define timelib_malloc malloc # define timelib_malloc malloc
# define timelib_realloc realloc # define timelib_realloc realloc
@ -310,8 +38,8 @@ typedef struct _timelib_tzdb {
# define timelib_free free # define timelib_free free
#endif #endif
#define TIMELIB_VERSION 201705 #define TIMELIB_VERSION 201602
#define TIMELIB_ASCII_VERSION "2017.05beta7" #define TIMELIB_ASCII_VERSION "2016.02"
#define TIMELIB_NONE 0x00 #define TIMELIB_NONE 0x00
#define TIMELIB_OVERRIDE_TIME 0x01 #define TIMELIB_OVERRIDE_TIME 0x01
@ -319,172 +47,51 @@ typedef struct _timelib_tzdb {
#define TIMELIB_UNSET -99999 #define TIMELIB_UNSET -99999
/* An entry for each of these error codes is also in the #define TIMELIB_SPECIAL_WEEKDAY 0x01
* timelib_error_messages array in timelib.c */ #define TIMELIB_SPECIAL_DAY_OF_WEEK_IN_MONTH 0x02
#define TIMELIB_ERROR_NO_ERROR 0x00 #define TIMELIB_SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH 0x03
#define TIMELIB_ERROR_CANNOT_ALLOCATE 0x01
#define TIMELIB_ERROR_CORRUPT_TRANSITIONS_DONT_INCREASE 0x02
#define TIMELIB_ERROR_CORRUPT_NO_64BIT_PREAMBLE 0x03
#define TIMELIB_ERROR_CORRUPT_NO_ABBREVIATION 0x04
#define TIMELIB_ERROR_UNSUPPORTED_VERSION 0x05
#define TIMELIB_ERROR_NO_SUCH_TIMEZONE 0x06
#ifdef __cplusplus #define TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH 0x01
extern "C" { #define TIMELIB_SPECIAL_LAST_DAY_OF_MONTH 0x02
#ifndef LONG_MAX
#define LONG_MAX 2147483647L
#endif
#ifndef LONG_MIN
#define LONG_MIN (- LONG_MAX - 1)
#endif
#if defined(_MSC_VER) && !defined(strcasecmp)
#define strcasecmp stricmp
#endif
#if defined(_MSC_VER) && !defined(strncasecmp)
#define strncasecmp strnicmp
#endif #endif
/* Function pointers */ /* Function pointers */
typedef timelib_tzinfo* (*timelib_tz_get_wrapper)(char *tzname, const timelib_tzdb *tzdb, int *error_code); typedef timelib_tzinfo* (*timelib_tz_get_wrapper)(char *tzname, const timelib_tzdb *tzdb);
/* From dow.c */ /* From dow.c */
/* Calculates the day of the week from y, m, and d. 0=Sunday..6=Saturday */
timelib_sll timelib_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d); timelib_sll timelib_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d);
/* Calculates the day of the ISO week from y, m, and d. 1=Monday, 7=Sunday */
timelib_sll timelib_iso_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d); timelib_sll timelib_iso_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d);
/* Calculates the day of the year according to y-m-d. 0=Jan 1st..364/365=Dec
* 31st */
timelib_sll timelib_day_of_year(timelib_sll y, timelib_sll m, timelib_sll d); timelib_sll timelib_day_of_year(timelib_sll y, timelib_sll m, timelib_sll d);
timelib_sll timelib_daynr_from_weeknr(timelib_sll y, timelib_sll w, timelib_sll d);
/* Calculates the day of the year according to y-w-dow. 0..364/365 */
timelib_sll timelib_daynr_from_weeknr(timelib_sll iy, timelib_sll iw, timelib_sll id);
/* Calculates the number of days in month m for year y. 28..31 */
timelib_sll timelib_days_in_month(timelib_sll y, timelib_sll m); timelib_sll timelib_days_in_month(timelib_sll y, timelib_sll m);
/* Calculates the ISO year and week from y, m, and d, into iw and iy */
void timelib_isoweek_from_date(timelib_sll y, timelib_sll m, timelib_sll d, timelib_sll *iw, timelib_sll *iy); void timelib_isoweek_from_date(timelib_sll y, timelib_sll m, timelib_sll d, timelib_sll *iw, timelib_sll *iy);
/* Calculates the ISO year, week, and day of week from y, m, and d, into iy,
* iw, and id */
void timelib_isodate_from_date(timelib_sll y, timelib_sll m, timelib_sll d, timelib_sll *iy, timelib_sll *iw, timelib_sll *id);
/* Calculates the year, month, and day from iy, iw, and iw, into y, m, and d */
void timelib_date_from_isodate(timelib_sll iy, timelib_sll iw, timelib_sll id, timelib_sll *y, timelib_sll *m, timelib_sll *d);
/* Returns true if h, i and s fit in the range 00:00:00..23:59:59, false
* otherwise */
int timelib_valid_time(timelib_sll h, timelib_sll i, timelib_sll s); int timelib_valid_time(timelib_sll h, timelib_sll i, timelib_sll s);
/* Returns true if m fits in the range 1..12, and d fits in the range
* 1..<days-in-month> for year y */
int timelib_valid_date(timelib_sll y, timelib_sll m, timelib_sll d); int timelib_valid_date(timelib_sll y, timelib_sll m, timelib_sll d);
/* From parse_date.re */ /* From parse_date.re */
/* Parses the date/time string in 's' with length 'len' into the constituent
* parts of timelib_time*.
*
* Depending on the contents of the string 's', not all elements might be
* filled. You can check whether a specific element has been parsed by
* comparing with the TIMELIB_UNSET define.
*
* If errors occur, this function keeps already parsed elements in the
* returned timelib_time* value.
*
* If the **errors points to a timelib_error_container variable, warnings
* and errors will be recorded. You are responsible for freeing the stored
* information with timelib_error_container_dtor(). To see whether errors have
* occured, inspect errors->errors_count. To see whether warnings have occured,
* inspect errors->warnings_count.
*
* The returned timelib_time* value is dynamically allocated and should be
* freed with timelib_time_dtor().
*/
timelib_time *timelib_strtotime(char *s, size_t len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper); timelib_time *timelib_strtotime(char *s, size_t len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper);
/* Parses the date/time string in 's' with length 'len' into the constituent
* parts of timelib_time* according to the format in 'format'.
*
* Depending on the contents of the string 's', not all elements might be
* filled. You can check whether a specific element has been parsed by
* comparing with the TIMELIB_UNSET define.
*
* If errors occur, this function keeps already parsed elements in the
* returned timelib_time* value.
*
* If the **errors points to a timelib_error_container variable, warnings
* and errors will be recorded. You are responsible for freeing the stored
* information with timelib_error_container_dtor(). To see whether errors have
* occured, inspect errors->errors_count. To see whether warnings have occured,
* inspect errors->warnings_count.
*
* The returned timelib_time* value is dynamically allocated and should be
* freed with timelib_time_dtor().
*/
timelib_time *timelib_parse_from_format(char *format, char *s, size_t len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper); timelib_time *timelib_parse_from_format(char *format, char *s, size_t len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper);
/* Fills the gaps in the parsed timelib_time with information from the reference date/time in 'now'
*
* If any of the 'parsed' y, m, d, h, i or s parameters is unset (TIMELIB_UNSET):
* - if microtime (us) is unset, then the us of the parsed time is set to 0.
* - else if microtime (us) is unset and 'now'->'us' is set, use it, otherwise use 0.
*
* For either of the 'parsed' y, m, d, h, i, s, z (utc offset in seconds) or
* dst is unset, set it to the corresponding value in 'now' if set, otherwise
* set it to 0.
*
* It duplicates tz_abbr if unset in 'parsed' but set in 'now'.
*
* It duplicates tz_info if unset in 'parsed', but set in 'now' unless
* TIMELIB_NO_CLONE is passed, in which case only the pointer in 'parsed' is
* set to 'now'.
*
* If the option TIMELIB_OVERRIDE_TIME is passed and the parsed date/time has
* no time portion, the function will ignore the time aspect in 'now' and
* instead fill it with zeros.
*/
void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options); void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options);
/* Tries to convert a time zone abbreviation, gmtoffset and/or isdst flag
* combination to a time zone identifier.
*
* If 'abbr' is either 'utc' or 'gmt' (case insensitve) then "UTC" is
* returned.
*
* It first uses the data in the timezonemap.h file to find a matching
* abbreviation/GMT offset combination. If not found, it uses the data in
* fallbackmap.h to match only the GMT offset/isdst flag to try to find a
* match. If nothing is found, NULL is returned.
*
* The returned char* is not duplicated, and should not be freed.
*/
char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst); char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst);
/* Returns an array of known time zone abbreviations
*
* This file is generated from the time zone database through the
* gettzmapping.php scripts, which requires that an up-to-date time zone
* database is used with the PHP binary that runs the script.
*
* Each item in the returned list contains the abbreviation, a flag whether
* it's an abbreviation used with DST, the UTC offset in seconds, and the name
* of the time zone identifier that this abbreviation belongs to.
*
* The order for each specific abbreviation is controlled through the
* preference list in the gettzmapping.php script. Time zones that match the
* pattern ±\d{2,4} are excluded
*/
const timelib_tz_lookup_table *timelib_timezone_abbreviations_list(void); const timelib_tz_lookup_table *timelib_timezone_abbreviations_list(void);
timelib_long timelib_parse_tz_cor(char**);
/**
* DEPRECATED, but still used by PHP.
*/
timelib_long timelib_parse_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_wrapper);
/* From parse_iso_intervals.re */ /* From parse_iso_intervals.re */
/**
* Parses a subset of an ISO 8601 intervals specification string into its
* constituent parts.
*
* If the **errors points to a timelib_error_container variable, warnings
* and errors will be recorded. You are responsible for freeing the stored
* information with timelib_error_container_dtor(). To see whether errors have
* occured, inspect errors->errors_count. To see whether warnings have occured,
* inspect errors->warnings_count.
*/
void timelib_strtointerval(char *s, size_t len, void timelib_strtointerval(char *s, size_t len,
timelib_time **begin, timelib_time **end, timelib_time **begin, timelib_time **end,
timelib_rel_time **period, int *recurrences, timelib_rel_time **period, int *recurrences,
@ -492,395 +99,66 @@ void timelib_strtointerval(char *s, size_t len,
/* From tm2unixtime.c */ /* From tm2unixtime.c */
/**
* Uses the y/m/d/h/i/s fields to calculate and store the equivalent timestamp
* in the sse field.
*
* It uses the time zone information associated with 'time' to account for the
* right UTC offset and/or DST rules. You can associate time zone information
* with the timelib_set_timezone_* functions (see below).
*
* If the type is 'TIMELIB_ZONETYPE_ID' and there is no associated tzinfo, it
* will use the second argument 'tzi' to provide the rules necessary to
* calculate the right timestamp.
*/
void timelib_update_ts(timelib_time* time, timelib_tzinfo* tzi); void timelib_update_ts(timelib_time* time, timelib_tzinfo* tzi);
/**
* Takes the information from the y/m/d/h/i/s fields and makes sure their
* values are in the right range.
*
* If a value under- or overflows it will adjust the larger measure up (or
* down). It also takes into account leap days.
*/
void timelib_do_normalize(timelib_time *base); void timelib_do_normalize(timelib_time *base);
/**
* Takes the information from the y/m/d/h/i/s fields of 'rt' and makes sure
* their values are in the right range.
*
* If a value under- or overflows it will adjust the larger measure up (or
* down). As this function operates on a *relative date/time*, it also takes
* into account leap days and correctly accounts for the difference depending
* on the base date/time in 'base'.
*/
void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt); void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt);
/* From unixtime2tm.c */ /* From unixtime2tm.c */
int timelib_apply_localtime(timelib_time *t, unsigned int localtime);
/**
* Takes the unix timestamp in seconds from 'ts' and populates the y/m/d/h/i/s
* fields of 'tm' without taking time zones into account
*/
void timelib_unixtime2gmt(timelib_time* tm, timelib_sll ts); void timelib_unixtime2gmt(timelib_time* tm, timelib_sll ts);
/**
* Takes the Unix timestamp from 'ts', and calculates the y/m/d/h/i/s fields
* according to the time zone information attached to 'tm'.
*/
void timelib_unixtime2local(timelib_time *tm, timelib_sll ts); void timelib_unixtime2local(timelib_time *tm, timelib_sll ts);
/**
* Takes the Unix timestamp stored in 'tm', and calculates the y/m/d/h/i/s
* fields according to the time zone information attached to 'tm'.
*/
void timelib_update_from_sse(timelib_time *tm); void timelib_update_from_sse(timelib_time *tm);
/**
* Attaches the UTC offset as time zone information to 't'.
*
* 'utc_offset' is in seconds East of UTC.
*/
void timelib_set_timezone_from_offset(timelib_time *t, timelib_sll utc_offset); void timelib_set_timezone_from_offset(timelib_time *t, timelib_sll utc_offset);
/**
* Attaches the information from 'abbr_info' as time zone information to 't'.
*
* The timelib_abbr_info struct contains an abbreviation ('abbr') which string
* value is duplicated, as well as a 'utc_offset' and 'dst' flag. It only
* supports a 'dst' change over of 1 hour.
*/
void timelib_set_timezone_from_abbr(timelib_time *t, timelib_abbr_info abbr_info); void timelib_set_timezone_from_abbr(timelib_time *t, timelib_abbr_info abbr_info);
/**
* Attaches the time zone information in 'tz' to to 't'.
*
* It fetches the right UTC offset that is currently stored in the time
* stamp field in 't' ('sse'), and assigns that to the 'z' field and 'dst'
* field (whether DST is in effect at the time). It also sets the current
* abbrevation to the 'tz_addr' field, making sure that if a value was already
* set it was freed.
*
* The time zone information in 'tz' is *not* duplicated into the 't' field so
* it should not be freed until all timelib_time* variables have been freed as
* well.
*/
void timelib_set_timezone(timelib_time *t, timelib_tzinfo *tz); void timelib_set_timezone(timelib_time *t, timelib_tzinfo *tz);
/* From parse_tz.c */ /* From parse_tz.c */
/**
* Returns whether the time zone ID 'timezone' is available in the time zone
* database as pointed to be 'tzdb'.
*/
int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb); int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb);
timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb);
/**
* Converts the binary stored time zone information from 'tzdb' for the time
* zone 'timeozne' into a structure the library can use for calculations.
*
* The function can be used on both timelib_builtin_db as well as a time zone
* db as opened by timelib_zoneinfo.
* The function will return null upon failure, and also set an error code
* through 'error_code'. 'error_code' must not be a null pointer. The error
* code is one of the TIMELIB_ERROR_* constants as listed above. These error
* constants can be converted into a string by timelib_get_error_message.
*
* This function allocates memory for the new time zone structure, which must
* be freed after use. Although it is recommended that a cache of each used
* time zone is kept.
*/
timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb, int *error_code);
/**
* Frees up the resources allocated by 'timelib_parse_tzfile'.
*/
void timelib_tzinfo_dtor(timelib_tzinfo *tz);
/**
* Deep-clones a timelib_tzinfo structure.
*
* This allocates resources that need to be freed with 'timelib_tzinfo_dtor'
*/
timelib_tzinfo* timelib_tzinfo_clone(timelib_tzinfo *tz);
/**
* Returns whether DST is active with time zone 'tz' for the time stamp 'ts'.
*
* Returns 0 if DST is not active, 1 if DST is active, or -1 if no transitions
* were available through 'tz'.
*/
int timelib_timestamp_is_in_dst(timelib_sll ts, timelib_tzinfo *tz); int timelib_timestamp_is_in_dst(timelib_sll ts, timelib_tzinfo *tz);
/**
* Returns offset information with time zone 'tz' for the time stamp 'ts'.
*
* The returned information contains: the offset in seconds East of UTC (in
* 'offset'), whether DST is active ('is_dst'), what the current time zone
* abbreviation is ('abbr') and the transition time that got to this state (in
* 'transistion_time');
*/
timelib_time_offset *timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *tz); timelib_time_offset *timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *tz);
/**
* Returns the UTC offset currently applicable for the information stored in 't'.
*
* The value returned is the UTC offset in seconds East.
*/
timelib_sll timelib_get_current_offset(timelib_time *t); timelib_sll timelib_get_current_offset(timelib_time *t);
/**
* Displays debugging information about the time zone information in 'tz'.
*/
void timelib_dump_tzinfo(timelib_tzinfo *tz); void timelib_dump_tzinfo(timelib_tzinfo *tz);
/**
* Returns a pointer to the built-in time zone database.
*
* You must *not* free the returned pointer as it is part of the text segment.
*/
const timelib_tzdb *timelib_builtin_db(void); const timelib_tzdb *timelib_builtin_db(void);
const timelib_tzdb_index_entry *timelib_timezone_builtin_identifiers_list(int *count);
/** timelib_long timelib_parse_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_wrapper);
* Returns a pointer to the start of an array containing a list of timezone identifiers.
*
* The amount of entries in the array is returned through the 'count' OUT parameter.
*
* Each entry contains the time zone ID ('id' field), and the position within the time zone
* information ('pos' field). The pos field should not be used.
*/
const timelib_tzdb_index_entry *timelib_timezone_identifiers_list(timelib_tzdb *tzdb, int *count);
/* From parse_zoneinfo.c */
/**
* Scans the directory and subdirectories of 'directory' for valid time zone files and builds
* a time zone database out of these files.
*
* Typically, the directory should point to '/usr/share/zoneinfo'.
*
* Unlike 'timelib_builtin_db', the return value of this function must be freed
* with the 'timelib_zoneinfo_dtor' function.
*/
timelib_tzdb *timelib_zoneinfo(char *directory);
/**
* Frees up the resources as created through 'timelib_zoneinfo'.
*
* This function must be used to free up all the resources that have been
* allocated while calling 'timelib_zoneinfo'.
*/
void timelib_zoneinfo_dtor(timelib_tzdb *tzdb);
/* From timelib.c */ /* From timelib.c */
timelib_tzinfo* timelib_tzinfo_ctor(char *name);
void timelib_time_tz_abbr_update(timelib_time* tm, char* tz_abbr);
void timelib_time_tz_name_update(timelib_time* tm, char* tz_name);
void timelib_tzinfo_dtor(timelib_tzinfo *tz);
timelib_tzinfo* timelib_tzinfo_clone(timelib_tzinfo *tz);
/**
* Returns a static string containing an error message belonging to a specific
* error code.
*/
const char *timelib_get_error_message(int error_code);
/**
* Allocates resources for the relative time structure.
*
* Must be freed with 'timelib_rel_time_dtor'.
*/
timelib_rel_time* timelib_rel_time_ctor(void); timelib_rel_time* timelib_rel_time_ctor(void);
/**
* Frees up the resources as allocated through 'timelib_rel_time_ctor'.
*/
void timelib_rel_time_dtor(timelib_rel_time* t); void timelib_rel_time_dtor(timelib_rel_time* t);
/**
* Creates a new timelib_rel_time resource and copies over the information
* from 'tz'.
*
* Must be freed with 'timelib_rel_time_dtor'.
*/
timelib_rel_time* timelib_rel_time_clone(timelib_rel_time *tz); timelib_rel_time* timelib_rel_time_clone(timelib_rel_time *tz);
/**
* Allocates resources for the time structure.
*
* Must be freed with 'timelib_time_dtor'.
*/
timelib_time* timelib_time_ctor(void); timelib_time* timelib_time_ctor(void);
void timelib_time_set_option(timelib_time* tm, int option, void* option_value);
/**
* Frees up the resources as allocated through 'timelib_time_ctor'.
*/
void timelib_time_dtor(timelib_time* t); void timelib_time_dtor(timelib_time* t);
/**
* Creates a new timelib_time resource and copies over the information
* from 'orig'.
*
* Must be freed with 'timelib_time_dtor'.
*/
timelib_time* timelib_time_clone(timelib_time* orig); timelib_time* timelib_time_clone(timelib_time* orig);
/**
* Compares two timelib_time structures and returns which one is earlier in
* time.
*
* To decide which comes earlier it uses the 'sse' (Seconds Since Epoch) and
* 'us' (microseconds) fields.
*
* Returns -1 if t1 < t2, 0 if t1 == t2, and -1 if t1 > t2.
*/
int timelib_time_compare(timelib_time *t1, timelib_time *t2); int timelib_time_compare(timelib_time *t1, timelib_time *t2);
/**
* Allocates resources for the time offset structure.
*
* Must be freed with 'timelib_time_offset_dtor'.
*/
timelib_time_offset* timelib_time_offset_ctor(void); timelib_time_offset* timelib_time_offset_ctor(void);
/**
* Frees up the resources as allocated through 'timelib_time_offset_ctor'.
*/
void timelib_time_offset_dtor(timelib_time_offset* t); void timelib_time_offset_dtor(timelib_time_offset* t);
/**
* Frees up the resources allocated while converting strings to timelib_time
* structures with the timelib_strtotime and timelib_strtointerval functions.
*/
void timelib_error_container_dtor(timelib_error_container *errors); void timelib_error_container_dtor(timelib_error_container *errors);
/**
* Converts the 'sse' value of 'd' to a timelib_long type.
*
* If the value fits in the TIMELIB_LONG_MIN and TIMELIB_LONG_MAX range, the
* value is cast to (timelib_long) and returned. If *error is not a NULL
* pointer, it will be set to 0.
*
* If the value does *not* fit in the range, the function returns 0 and if
* *error is not a NULL pointer, it will be set to 1.
*
* timelib_long is a 32 bit signed long integer on 32 bit platforms, and a 64
* bit signed long long integer on 64 bit platforms. In other words, it makes
* sure that the value in 'sse' (which is always a signed long long 64 bit
* integer) can be used safely outside of the library.
*/
timelib_long timelib_date_to_int(timelib_time *d, int *error); timelib_long timelib_date_to_int(timelib_time *d, int *error);
/**
* Displays debugging information about the date/time information stored in 'd'.
*
* 'options' is a bit field, where:
* - 1 controls whether the relative time portion is shown.
* - 2 controls whether the zone type is shown.
*/
void timelib_dump_date(timelib_time *d, int options); void timelib_dump_date(timelib_time *d, int options);
/**
* Displays debugging information about the relative time information stored
* in 'd'.
*/
void timelib_dump_rel_time(timelib_rel_time *d); void timelib_dump_rel_time(timelib_rel_time *d);
/**
* Converts a decimal hour into hour/min/sec components
*/
void timelib_decimal_hour_to_hms(double h, int *hour, int *min, int *sec); void timelib_decimal_hour_to_hms(double h, int *hour, int *min, int *sec);
timelib_long timelib_parse_tz_cor(char **ptr);
/**
* Converts hour/min/sec values into a decimal hour
*/
void timelib_hms_to_decimal_hour(int hour, int min, int sec, double *h);
/* from astro.c */ /* from astro.c */
double timelib_ts_to_juliandate(timelib_sll ts);
/**
* Converts the Unix Epoch time stamp 'ts' to a Julian Day
*
* The value returned is the number of whole days since -4714-11-24T12:00:00 UTC
* (in the proleptic Gregorian calendar):
* https://en.wikipedia.org/wiki/Julian_day
*/
double timelib_ts_to_julianday(timelib_sll ts);
/**
* Converts the Unix Epoch time stamp 'ts' to the J2000 epoch
*
* The value returned is the number of whole days since 2000-01-01T12:00:00
* UTC: https://en.wikipedia.org/wiki/Epoch_(astronomy)#Julian_years_and_J2000
*/
double timelib_ts_to_j2000(timelib_sll ts);
/**
* Calculates when the Sun is above a certain latitude.
*
* Parameters:
* - time: A timelib_time time describing that needs to specific midnight for a
* specific day.
* - lon: The longitude of the observer (East positive, West negative).
* - lat: The latitude of the observer (North positive, South negative).
* - altit: The altitude. Set to -35/60 for rise/set, -6 for civil twilight,
* -12 for nautical, and -18 for astronomical twilight.
* - upper_limb: set to non-zero for rise/set calculations, and 0 for twilight
* calculations.
*
* Out Parameters:
* - h_rise: The decimal hour when the Sun rises
* - h_set: The decimal hour when the Sun sets
* - ts_rise: The Unix timestamp of the Sun rising
* - ts_set: The Unix timestamp of the Sun setting
* - ts_transit: The Unix timestmap of the Sun transitting through South
*
* Return Values:
* - 0: The Sun rises and sets.
* - +1: The Sun is always above the horizon. (ts_rise is set to ts_transit -
* (12 * 3600); ts_set is set to ts_transit + (12 * 3600).
* - -1: The Sun is awlays below the horizon. (ts_rise and ts_set are set
* to ts_transit)
*/
int timelib_astro_rise_set_altitude(timelib_time *time, double lon, double lat, double altit, int upper_limb, double *h_rise, double *h_set, timelib_sll *ts_rise, timelib_sll *ts_set, timelib_sll *ts_transit); int timelib_astro_rise_set_altitude(timelib_time *time, double lon, double lat, double altit, int upper_limb, double *h_rise, double *h_set, timelib_sll *ts_rise, timelib_sll *ts_set, timelib_sll *ts_transit);
/* from interval.c */ /* from interval.c */
/**
* Calculates the difference between two times
*
* The result is a timelib_rel_time structure that describes how you can
* convert from 'one' to 'two' with 'timelib_add'. This does *not* necessarily
* mean that you can go from 'two' to 'one' by using 'timelib_sub' due to the
* way months and days are calculated.
*/
timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two); timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two);
/**
* Adds the relative time information 'interval' to the base time 't'.
*
* This can be a relative time as created by 'timelib_diff', but also by more
* complex statements such as "next workday".
*/
timelib_time *timelib_add(timelib_time *t, timelib_rel_time *interval); timelib_time *timelib_add(timelib_time *t, timelib_rel_time *interval);
/**
* Subtracts the relative time information 'interval' to the base time 't'.
*
* This can be a relative time as created by 'timelib_diff'. Unlike with
* 'timelib_add', this does not support more complex statements such as "next
* workday".
*/
timelib_time *timelib_sub(timelib_time *t, timelib_rel_time *interval); timelib_time *timelib_sub(timelib_time *t, timelib_rel_time *interval);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif #endif

View file

@ -69,15 +69,12 @@ TL_CHECK_INT_TYPE(uint32_t)
dnl Check for headers needed by timelib dnl Check for headers needed by timelib
AC_CHECK_HEADERS([ \ AC_CHECK_HEADERS([ \
sys/time.h \
sys/types.h \ sys/types.h \
inttypes.h \
stdint.h \ stdint.h \
dirent.h \
string.h \ string.h \
strings.h \ stdlib.h
unistd.h \
io.h
]) ])
dnl Check for strtoll, atoll dnl Check for strtoll, atoll
AC_CHECK_FUNCS(strtoll atoll strftime gettimeofday) AC_CHECK_FUNCS(strtoll atoll strftime)

View file

@ -1,158 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Derick Rethans
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef __TIMELIB_PRIVATE_H__
#define __TIMELIB_PRIVATE_H__
#ifdef HAVE_SETLOCALE
# include "locale.h"
#endif
#ifdef HAVE_TIMELIB_CONFIG_H
# include "timelib_config.h"
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#ifdef _WIN32
# ifdef HAVE_WINSOCK2_H
# include <winsock2.h>
# endif
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if defined(HAVE_STDINT_H)
# include <stdint.h>
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#if HAVE_IO_H
# include <io.h>
#endif
#if HAVE_DIRENT_H
# include <dirent.h>
#endif
#include <stdio.h>
#if HAVE_LIMITS_H
#include <limits.h>
#endif
#define TIMELIB_SECOND 1
#define TIMELIB_MINUTE 2
#define TIMELIB_HOUR 3
#define TIMELIB_DAY 4
#define TIMELIB_MONTH 5
#define TIMELIB_YEAR 6
#define TIMELIB_WEEKDAY 7
#define TIMELIB_SPECIAL 8
#define TIMELIB_MICROSEC 9
#define TIMELIB_SPECIAL_WEEKDAY 0x01
#define TIMELIB_SPECIAL_DAY_OF_WEEK_IN_MONTH 0x02
#define TIMELIB_SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH 0x03
#define TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH 0x01
#define TIMELIB_SPECIAL_LAST_DAY_OF_MONTH 0x02
#define SECS_PER_ERA TIMELIB_LL_CONST(12622780800)
#define SECS_PER_DAY 86400
#define DAYS_PER_YEAR 365
#define DAYS_PER_LYEAR 366
/* 400*365 days + 97 leap days */
#define DAYS_PER_LYEAR_PERIOD 146097
#define YEARS_PER_LYEAR_PERIOD 400
#define TIMELIB_TZINFO_PHP 0x01
#define TIMELIB_TZINFO_ZONEINFO 0x02
#define timelib_is_leap(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
#define TIMELIB_DEBUG(s) if (0) { s }
#define TIMELIB_TIME_FREE(m) \
if (m) { \
timelib_free(m); \
m = NULL; \
}
typedef struct ttinfo
{
int32_t offset;
int isdst;
unsigned int abbr_idx;
unsigned int isstdcnt;
unsigned int isgmtcnt;
} ttinfo;
typedef struct tlinfo
{
int32_t trans;
int32_t offset;
} tlinfo;
#ifndef LONG_MAX
#define LONG_MAX 2147483647L
#endif
#ifndef LONG_MIN
#define LONG_MIN (- LONG_MAX - 1)
#endif
#if defined(_MSC_VER) && !defined(strcasecmp)
#define strcasecmp stricmp
#endif
#if defined(_MSC_VER) && !defined(strncasecmp)
#define strncasecmp strnicmp
#endif
/* From unixtime2tm.c */
int timelib_apply_localtime(timelib_time *t, unsigned int localtime);
/* From parse_tz.c */
void timelib_time_tz_abbr_update(timelib_time* tm, char* tz_abbr);
#endif

View file

@ -0,0 +1,315 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Derick Rethans
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef __TIMELIB_STRUCTS_H__
#define __TIMELIB_STRUCTS_H__
#ifdef HAVE_TIMELIB_CONFIG_H
# include "timelib_config.h"
#endif
#ifndef TIMELIB_OMIT_STDINT
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if defined(HAVE_INTTYPES_H)
#include <inttypes.h>
#elif defined(HAVE_STDINT_H)
#include <stdint.h>
#endif
# ifndef HAVE_INT32_T
# if SIZEOF_INT == 4
typedef int int32_t;
# elif SIZEOF_LONG == 4
typedef long int int32_t;
# endif
# endif
# ifndef HAVE_UINT32_T
# if SIZEOF_INT == 4
typedef unsigned int uint32_t;
# elif SIZEOF_LONG == 4
typedef unsigned long int uint32_t;
# endif
# endif
#ifdef _WIN32
# if _MSC_VER >= 1600
# include <stdint.h>
# endif
# ifndef SIZEOF_INT
# define SIZEOF_INT 4
# endif
# ifndef SIZEOF_LONG
# define SIZEOF_LONG 4
# endif
# ifndef int32_t
typedef __int32 int32_t;
# endif
# ifndef uint32_t
typedef unsigned __int32 uint32_t;
# endif
# ifndef int64_t
typedef __int64 int64_t;
# endif
# ifndef uint64_t
typedef unsigned __int64 uint64_t;
# endif
# ifndef PRId32
# define PRId32 "I32d"
# endif
# ifndef PRIu32
# define PRIu32 "I32u"
# endif
# ifndef PRId64
# define PRId64 "I64d"
# endif
# ifndef PRIu64
# define PRIu64 "I64u"
# endif
# ifndef INT32_MAX
#define INT32_MAX _I32_MAX
# endif
# ifndef INT32_MIN
#define INT32_MIN ((int32_t)_I32_MIN)
# endif
# ifndef UINT32_MAX
#define UINT32_MAX _UI32_MAX
# endif
# ifndef INT64_MIN
#define INT64_MIN ((int64_t)_I64_MIN)
# endif
# ifndef INT64_MAX
#define INT64_MAX _I64_MAX
# endif
# ifndef UINT64_MAX
#define UINT64_MAX _UI64_MAX
# endif
#endif
#endif /* TIMELIB_OMIT_STDINT */
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#if defined(__x86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)
typedef int64_t timelib_long;
typedef uint64_t timelib_ulong;
# define TIMELIB_LONG_MAX INT64_MAX
# define TIMELIB_LONG_MIN INT64_MIN
# define TIMELIB_ULONG_MAX UINT64_MAX
# define TIMELIB_LONG_FMT "%" PRId64
# define TIMELIB_ULONG_FMT "%" PRIu64
#else
typedef int32_t timelib_long;
typedef uint32_t timelib_ulong;
# define TIMELIB_LONG_MAX INT32_MAX
# define TIMELIB_LONG_MIN INT32_MIN
# define TIMELIB_ULONG_MAX UINT32_MAX
# define TIMELIB_LONG_FMT "%" PRId32
# define TIMELIB_ULONG_FMT "%" PRIu32
#endif
#if defined(_MSC_VER)
typedef uint64_t timelib_ull;
typedef int64_t timelib_sll;
# define TIMELIB_LL_CONST(n) n ## i64
#else
typedef unsigned long long timelib_ull;
typedef signed long long timelib_sll;
# define TIMELIB_LL_CONST(n) n ## ll
#endif
typedef struct ttinfo
{
int32_t offset;
int isdst;
unsigned int abbr_idx;
unsigned int isstdcnt;
unsigned int isgmtcnt;
} ttinfo;
typedef struct tlinfo
{
int32_t trans;
int32_t offset;
} tlinfo;
typedef struct tlocinfo
{
char country_code[3];
double latitude;
double longitude;
char *comments;
} tlocinfo;
typedef struct timelib_tzinfo
{
char *name;
struct {
uint32_t ttisgmtcnt;
uint32_t ttisstdcnt;
uint32_t leapcnt;
uint32_t timecnt;
uint32_t typecnt;
uint32_t charcnt;
} bit32;
struct {
uint64_t ttisgmtcnt;
uint64_t ttisstdcnt;
uint64_t leapcnt;
uint64_t timecnt;
uint64_t typecnt;
uint64_t charcnt;
} bit64;
int32_t *trans;
unsigned char *trans_idx;
ttinfo *type;
char *timezone_abbr;
tlinfo *leap_times;
unsigned char bc;
tlocinfo location;
} timelib_tzinfo;
typedef struct timelib_special {
unsigned int type;
timelib_sll amount;
} timelib_special;
typedef struct timelib_rel_time {
timelib_sll y, m, d; /* Years, Months and Days */
timelib_sll h, i, s; /* Hours, mInutes and Seconds */
int weekday; /* Stores the day in 'next monday' */
int weekday_behavior; /* 0: the current day should *not* be counted when advancing forwards; 1: the current day *should* be counted */
int first_last_day_of;
int invert; /* Whether the difference should be inverted */
timelib_sll days; /* Contains the number of *days*, instead of Y-M-D differences */
timelib_special special;
unsigned int have_weekday_relative, have_special_relative;
} timelib_rel_time;
typedef struct timelib_time_offset {
int32_t offset;
unsigned int leap_secs;
unsigned int is_dst;
char *abbr;
timelib_sll transistion_time;
} timelib_time_offset;
typedef struct timelib_time {
timelib_sll y, m, d; /* Year, Month, Day */
timelib_sll h, i, s; /* Hour, mInute, Second */
double f; /* Fraction */
int z; /* GMT offset in minutes */
char *tz_abbr; /* Timezone abbreviation (display only) */
timelib_tzinfo *tz_info; /* Timezone structure */
signed int dst; /* Flag if we were parsing a DST zone */
timelib_rel_time relative;
timelib_sll sse; /* Seconds since epoch */
unsigned int have_time, have_date, have_zone, have_relative, have_weeknr_day;
unsigned int sse_uptodate; /* !0 if the sse member is up to date with the date/time members */
unsigned int tim_uptodate; /* !0 if the date/time members are up to date with the sse member */
unsigned int is_localtime; /* 1 if the current struct represents localtime, 0 if it is in GMT */
unsigned int zone_type; /* 1 time offset,
* 3 TimeZone identifier,
* 2 TimeZone abbreviation */
} timelib_time;
typedef struct timelib_abbr_info {
timelib_sll utc_offset;
char *abbr;
int dst;
} timelib_abbr_info;
typedef struct timelib_error_message {
int position;
char character;
char *message;
} timelib_error_message;
typedef struct timelib_error_container {
struct timelib_error_message *error_messages;
struct timelib_error_message *warning_messages;
int error_count;
int warning_count;
} timelib_error_container;
typedef struct _timelib_tz_lookup_table {
char *name;
int type;
float gmtoffset;
char *full_tz_name;
} timelib_tz_lookup_table;
typedef struct _timelib_tzdb_index_entry {
char *id;
unsigned int pos;
} timelib_tzdb_index_entry;
typedef struct _timelib_tzdb {
char *version;
int index_size;
const timelib_tzdb_index_entry *index;
const unsigned char *data;
} timelib_tzdb;
#define TIMELIB_ZONETYPE_OFFSET 1
#define TIMELIB_ZONETYPE_ABBR 2
#define TIMELIB_ZONETYPE_ID 3
#define SECS_PER_ERA TIMELIB_LL_CONST(12622780800)
#define SECS_PER_DAY 86400
#define DAYS_PER_YEAR 365
#define DAYS_PER_LYEAR 366
/* 400*365 days + 97 leap days */
#define DAYS_PER_LYEAR_PERIOD 146097
#define YEARS_PER_LYEAR_PERIOD 400
#define timelib_is_leap(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
#define TIMELIB_DEBUG(s) if (0) { s }
#endif

File diff suppressed because it is too large Load diff

View file

@ -23,7 +23,6 @@
*/ */
#include "timelib.h" #include "timelib.h"
#include "timelib_private.h"
/* jan feb mrt apr may jun jul aug sep oct nov dec */ /* jan feb mrt apr may jun jul aug sep oct nov dec */
static int month_tab_leap[12] = { -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; static int month_tab_leap[12] = { -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
@ -33,18 +32,6 @@ static int month_tab[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 24
static int days_in_month_leap[13] = { 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; static int days_in_month_leap[13] = { 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static int days_in_month[13] = { 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; static int days_in_month[13] = { 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static void do_range_limit_fraction(timelib_sll *fraction, timelib_sll *seconds)
{
if (*fraction < 0) {
*fraction += 1000000;
*seconds -= 1;
}
if (*fraction > 1000000) {
*fraction -= 1000000;
*seconds += 1;
}
}
static void do_range_limit(timelib_sll start, timelib_sll end, timelib_sll adj, timelib_sll *a, timelib_sll *b) static void do_range_limit(timelib_sll start, timelib_sll end, timelib_sll adj, timelib_sll *a, timelib_sll *b)
{ {
if (*a < start) { if (*a < start) {
@ -203,47 +190,13 @@ void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt)
do_range_limit(0, 12, 12, &rt->m, &rt->y); do_range_limit(0, 12, 12, &rt->m, &rt->y);
} }
#define EPOCH_DAY 719468
static void magic_date_calc(timelib_time *time)
{
timelib_sll y, ddd, mi, mm, dd, g;
/* The algorithm doesn't work before the year 1 */
if (time->d < -719498) {
return;
}
g = time->d + EPOCH_DAY - 1;
y = (10000 * g + 14780) / 3652425;
ddd = g - ((365*y) + (y/4) - (y/100) + (y/400));
if (ddd < 0) {
y--;
ddd = g - ((365*y) + (y/4) - (y/100) + (y/400));
}
mi = (100 * ddd + 52) / 3060;
mm = ((mi + 2) % 12) + 1;
y = y + (mi + 2) / 12;
dd = ddd - ((mi * 306 + 5) / 10) + 1;
time->y = y;
time->m = mm;
time->d = dd;
}
void timelib_do_normalize(timelib_time* time) void timelib_do_normalize(timelib_time* time)
{ {
if (time->us != TIMELIB_UNSET) do_range_limit_fraction(&time->us, &time->s);
if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->s, &time->i); if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->s, &time->i);
if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->i, &time->h); if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->i, &time->h);
if (time->s != TIMELIB_UNSET) do_range_limit(0, 24, 24, &time->h, &time->d); if (time->s != TIMELIB_UNSET) do_range_limit(0, 24, 24, &time->h, &time->d);
do_range_limit(1, 13, 12, &time->m, &time->y); do_range_limit(1, 13, 12, &time->m, &time->y);
/* Short cut if we're doing things against the Epoch */
if (time->y == 1970 && time->m == 1 && time->d != 1) {
magic_date_calc(time);
}
do {} while (do_range_limit_days(&time->y, &time->m, &time->d)); do {} while (do_range_limit_days(&time->y, &time->m, &time->d));
do_range_limit(1, 13, 12, &time->m, &time->y); do_range_limit(1, 13, 12, &time->m, &time->y);
} }
@ -256,8 +209,6 @@ static void do_adjust_relative(timelib_time* time)
timelib_do_normalize(time); timelib_do_normalize(time);
if (time->have_relative) { if (time->have_relative) {
time->us += time->relative.us;
time->s += time->relative.s; time->s += time->relative.s;
time->i += time->relative.i; time->i += time->relative.i;
time->h += time->relative.h; time->h += time->relative.h;
@ -433,15 +384,16 @@ static timelib_sll do_adjust_timezone(timelib_time *tz, timelib_tzinfo *tzi)
case TIMELIB_ZONETYPE_OFFSET: case TIMELIB_ZONETYPE_OFFSET:
tz->is_localtime = 1; tz->is_localtime = 1;
return -tz->z; return tz->z * 60;
break; break;
case TIMELIB_ZONETYPE_ABBR: { case TIMELIB_ZONETYPE_ABBR: {
timelib_sll tmp; timelib_sll tmp;
tz->is_localtime = 1; tz->is_localtime = 1;
tmp = -tz->z; tmp = tz->z;
tmp -= tz->dst * 3600; tmp -= tz->dst * 60;
tmp *= 60;
return tmp; return tmp;
} }
break; break;
@ -455,19 +407,19 @@ static timelib_sll do_adjust_timezone(timelib_time *tz, timelib_tzinfo *tzi)
if (tzi) { if (tzi) {
timelib_time_offset *before, *after; timelib_time_offset *before, *after;
timelib_sll tmp; timelib_sll tmp;
int in_transition; int in_transistion;
tz->is_localtime = 1; tz->is_localtime = 1;
before = timelib_get_time_zone_info(tz->sse, tzi); before = timelib_get_time_zone_info(tz->sse, tzi);
after = timelib_get_time_zone_info(tz->sse - before->offset, tzi); after = timelib_get_time_zone_info(tz->sse - before->offset, tzi);
timelib_set_timezone(tz, tzi); timelib_set_timezone(tz, tzi);
in_transition = ( in_transistion = (
((tz->sse - after->offset) >= (after->transition_time + (before->offset - after->offset))) && ((tz->sse - after->offset) >= (after->transistion_time + (before->offset - after->offset))) &&
((tz->sse - after->offset) < after->transition_time) ((tz->sse - after->offset) < after->transistion_time)
); );
if ((before->offset != after->offset) && !in_transition) { if ((before->offset != after->offset) && !in_transistion) {
tmp = -after->offset; tmp = -after->offset;
} else { } else {
tmp = -tz->z; tmp = -tz->z;

View file

@ -23,7 +23,18 @@
*/ */
#include "timelib.h" #include "timelib.h"
#include "timelib_private.h"
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
static int month_tab_leap[12] = { -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; static int month_tab_leap[12] = { -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
static int month_tab[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; static int month_tab[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
@ -49,7 +60,7 @@ void timelib_unixtime2gmt(timelib_time* tm, timelib_sll ts)
if (ts >= 0) { if (ts >= 0) {
tmp_days = days + 1; tmp_days = days + 1;
if (tmp_days > DAYS_PER_LYEAR_PERIOD || tmp_days <= -DAYS_PER_LYEAR_PERIOD) { if (tmp_days >= DAYS_PER_LYEAR_PERIOD || tmp_days <= -DAYS_PER_LYEAR_PERIOD) {
cur_year += YEARS_PER_LYEAR_PERIOD * (tmp_days / DAYS_PER_LYEAR_PERIOD); cur_year += YEARS_PER_LYEAR_PERIOD * (tmp_days / DAYS_PER_LYEAR_PERIOD);
tmp_days -= DAYS_PER_LYEAR_PERIOD * (tmp_days / DAYS_PER_LYEAR_PERIOD); tmp_days -= DAYS_PER_LYEAR_PERIOD * (tmp_days / DAYS_PER_LYEAR_PERIOD);
} }
@ -138,7 +149,7 @@ void timelib_update_from_sse(timelib_time *tm)
switch (tm->zone_type) { switch (tm->zone_type) {
case TIMELIB_ZONETYPE_ABBR: case TIMELIB_ZONETYPE_ABBR:
case TIMELIB_ZONETYPE_OFFSET: { case TIMELIB_ZONETYPE_OFFSET: {
timelib_unixtime2gmt(tm, tm->sse + tm->z + (tm->dst * 3600)); timelib_unixtime2gmt(tm, tm->sse - (tm->z * 60) + (tm->dst * 3600));
goto cleanup; goto cleanup;
} }
@ -176,7 +187,7 @@ void timelib_unixtime2local(timelib_time *tm, timelib_sll ts)
int z = tm->z; int z = tm->z;
signed int dst = tm->dst; signed int dst = tm->dst;
timelib_unixtime2gmt(tm, ts + tm->z + (tm->dst * 3600)); timelib_unixtime2gmt(tm, ts - (tm->z * 60) + (tm->dst * 3600));
tm->sse = ts; tm->sse = ts;
tm->z = z; tm->z = z;

View file

@ -29,7 +29,6 @@
#include "php_date.h" #include "php_date.h"
#include "zend_interfaces.h" #include "zend_interfaces.h"
#include "lib/timelib.h" #include "lib/timelib.h"
#include "lib/timelib_private.h"
#include <time.h> #include <time.h>
#ifdef PHP_WIN32 #ifdef PHP_WIN32
@ -925,7 +924,6 @@ PHP_MINFO_FUNCTION(date)
static timelib_tzinfo *php_date_parse_tzfile(char *formal_tzname, const timelib_tzdb *tzdb) static timelib_tzinfo *php_date_parse_tzfile(char *formal_tzname, const timelib_tzdb *tzdb)
{ {
timelib_tzinfo *tzi; timelib_tzinfo *tzi;
int dummy_error_code;
if(!DATEG(tzcache)) { if(!DATEG(tzcache)) {
ALLOC_HASHTABLE(DATEG(tzcache)); ALLOC_HASHTABLE(DATEG(tzcache));
@ -936,14 +934,14 @@ static timelib_tzinfo *php_date_parse_tzfile(char *formal_tzname, const timelib_
return tzi; return tzi;
} }
tzi = timelib_parse_tzfile(formal_tzname, tzdb, &dummy_error_code); tzi = timelib_parse_tzfile(formal_tzname, tzdb);
if (tzi) { if (tzi) {
zend_hash_str_add_ptr(DATEG(tzcache), formal_tzname, strlen(formal_tzname), tzi); zend_hash_str_add_ptr(DATEG(tzcache), formal_tzname, strlen(formal_tzname), tzi);
} }
return tzi; return tzi;
} }
timelib_tzinfo *php_date_parse_tzfile_wrapper(char *formal_tzname, const timelib_tzdb *tzdb, int *dummy_error_code) timelib_tzinfo *php_date_parse_tzfile_wrapper(char *formal_tzname, const timelib_tzdb *tzdb)
{ {
return php_date_parse_tzfile(formal_tzname, tzdb); return php_date_parse_tzfile(formal_tzname, tzdb);
} }
@ -1094,13 +1092,13 @@ static zend_string *date_format(char *format, size_t format_len, timelib_time *t
if (localtime) { if (localtime) {
if (t->zone_type == TIMELIB_ZONETYPE_ABBR) { if (t->zone_type == TIMELIB_ZONETYPE_ABBR) {
offset = timelib_time_offset_ctor(); offset = timelib_time_offset_ctor();
offset->offset = (t->z + (t->dst * 3600)); offset->offset = (t->z - (t->dst * 60)) * -60;
offset->leap_secs = 0; offset->leap_secs = 0;
offset->is_dst = t->dst; offset->is_dst = t->dst;
offset->abbr = timelib_strdup(t->tz_abbr); offset->abbr = timelib_strdup(t->tz_abbr);
} else if (t->zone_type == TIMELIB_ZONETYPE_OFFSET) { } else if (t->zone_type == TIMELIB_ZONETYPE_OFFSET) {
offset = timelib_time_offset_ctor(); offset = timelib_time_offset_ctor();
offset->offset = (t->z); offset->offset = (t->z) * -60;
offset->leap_secs = 0; offset->leap_secs = 0;
offset->is_dst = 0; offset->is_dst = 0;
offset->abbr = timelib_malloc(9); /* GMT±xxxx\0 */ offset->abbr = timelib_malloc(9); /* GMT±xxxx\0 */
@ -1165,8 +1163,8 @@ static zend_string *date_format(char *format, size_t format_len, timelib_time *t
case 'H': length = slprintf(buffer, 32, "%02d", (int) t->h); break; case 'H': length = slprintf(buffer, 32, "%02d", (int) t->h); break;
case 'i': length = slprintf(buffer, 32, "%02d", (int) t->i); break; case 'i': length = slprintf(buffer, 32, "%02d", (int) t->i); break;
case 's': length = slprintf(buffer, 32, "%02d", (int) t->s); break; case 's': length = slprintf(buffer, 32, "%02d", (int) t->s); break;
case 'u': length = slprintf(buffer, 32, "%06d", (int) floor(t->us)); break; case 'u': length = slprintf(buffer, 32, "%06d", (int) floor(t->f * 1000000 + 0.5)); break;
case 'v': length = slprintf(buffer, 32, "%03d", (int) floor(t->us / 1000)); break; case 'v': length = slprintf(buffer, 32, "%03d", (int) floor(t->f * 1000 + 0.5)); break;
/* timezone */ /* timezone */
case 'I': length = slprintf(buffer, 32, "%d", localtime ? offset->is_dst : 0); break; case 'I': length = slprintf(buffer, 32, "%d", localtime ? offset->is_dst : 0); break;
@ -1304,13 +1302,13 @@ PHPAPI int php_idate(char format, time_t ts, int localtime)
if (!localtime) { if (!localtime) {
if (t->zone_type == TIMELIB_ZONETYPE_ABBR) { if (t->zone_type == TIMELIB_ZONETYPE_ABBR) {
offset = timelib_time_offset_ctor(); offset = timelib_time_offset_ctor();
offset->offset = (t->z + (t->dst * 3600)); offset->offset = (t->z - (t->dst * 60)) * -60;
offset->leap_secs = 0; offset->leap_secs = 0;
offset->is_dst = t->dst; offset->is_dst = t->dst;
offset->abbr = timelib_strdup(t->tz_abbr); offset->abbr = timelib_strdup(t->tz_abbr);
} else if (t->zone_type == TIMELIB_ZONETYPE_OFFSET) { } else if (t->zone_type == TIMELIB_ZONETYPE_OFFSET) {
offset = timelib_time_offset_ctor(); offset = timelib_time_offset_ctor();
offset->offset = (t->z + (t->dst * 3600)); offset->offset = (t->z - (t->dst * 60)) * -60;
offset->leap_secs = 0; offset->leap_secs = 0;
offset->is_dst = t->dst; offset->is_dst = t->dst;
offset->abbr = timelib_malloc(9); /* GMT±xxxx\0 */ offset->abbr = timelib_malloc(9); /* GMT±xxxx\0 */
@ -2258,9 +2256,9 @@ static HashTable *date_object_get_properties(zval *object) /* {{{ */
timelib_sll utc_offset = dateobj->time->z; timelib_sll utc_offset = dateobj->time->z;
ZSTR_LEN(tmpstr) = snprintf(ZSTR_VAL(tmpstr), sizeof("+05:00"), "%c%02d:%02d", ZSTR_LEN(tmpstr) = snprintf(ZSTR_VAL(tmpstr), sizeof("+05:00"), "%c%02d:%02d",
utc_offset < 0 ? '-' : '+', utc_offset > 0 ? '-' : '+',
abs(utc_offset / 3600), abs(utc_offset / 60),
abs(((utc_offset % 3600) / 60))); abs((utc_offset % 60)));
ZVAL_NEW_STR(&zv, tmpstr); ZVAL_NEW_STR(&zv, tmpstr);
} }
@ -2350,9 +2348,9 @@ static HashTable *date_object_get_properties_timezone(zval *object) /* {{{ */
zend_string *tmpstr = zend_string_alloc(sizeof("UTC+05:00")-1, 0); zend_string *tmpstr = zend_string_alloc(sizeof("UTC+05:00")-1, 0);
ZSTR_LEN(tmpstr) = snprintf(ZSTR_VAL(tmpstr), sizeof("+05:00"), "%c%02d:%02d", ZSTR_LEN(tmpstr) = snprintf(ZSTR_VAL(tmpstr), sizeof("+05:00"), "%c%02d:%02d",
tzobj->tzi.utc_offset < 0 ? '-' : '+', tzobj->tzi.utc_offset > 0 ? '-' : '+',
abs(tzobj->tzi.utc_offset / 3600), abs(tzobj->tzi.utc_offset / 60),
abs(((tzobj->tzi.utc_offset % 3600) / 60))); abs((tzobj->tzi.utc_offset % 60)));
ZVAL_NEW_STR(&zv, tmpstr); ZVAL_NEW_STR(&zv, tmpstr);
} }
@ -2949,10 +2947,10 @@ void php_date_do_return_parsed_time(INTERNAL_FUNCTION_PARAMETERS, timelib_time *
PHP_DATE_PARSE_DATE_SET_TIME_ELEMENT(minute, i); PHP_DATE_PARSE_DATE_SET_TIME_ELEMENT(minute, i);
PHP_DATE_PARSE_DATE_SET_TIME_ELEMENT(second, s); PHP_DATE_PARSE_DATE_SET_TIME_ELEMENT(second, s);
if (parsed_time->us == -99999) { if (parsed_time->f == -99999) {
add_assoc_bool(return_value, "fraction", 0); add_assoc_bool(return_value, "fraction", 0);
} else { } else {
add_assoc_double(return_value, "fraction", (double)parsed_time->us / 1000000.0); add_assoc_double(return_value, "fraction", parsed_time->f);
} }
zval_from_error_container(return_value, error); zval_from_error_container(return_value, error);
@ -3401,10 +3399,10 @@ PHP_FUNCTION(date_offset_get)
timelib_time_offset_dtor(offset); timelib_time_offset_dtor(offset);
break; break;
case TIMELIB_ZONETYPE_OFFSET: case TIMELIB_ZONETYPE_OFFSET:
RETVAL_LONG(dateobj->time->z); RETVAL_LONG(dateobj->time->z * -60);
break; break;
case TIMELIB_ZONETYPE_ABBR: case TIMELIB_ZONETYPE_ABBR:
RETVAL_LONG((dateobj->time->z + (3600 * dateobj->time->dst))); RETVAL_LONG((dateobj->time->z - (60 * dateobj->time->dst)) * -60);
break; break;
} }
return; return;
@ -3818,9 +3816,9 @@ PHP_FUNCTION(timezone_name_get)
timelib_sll utc_offset = tzobj->tzi.utc_offset; timelib_sll utc_offset = tzobj->tzi.utc_offset;
ZSTR_LEN(tmpstr) = snprintf(ZSTR_VAL(tmpstr), sizeof("+05:00"), "%c%02d:%02d", ZSTR_LEN(tmpstr) = snprintf(ZSTR_VAL(tmpstr), sizeof("+05:00"), "%c%02d:%02d",
utc_offset < 0 ? '-' : '+', utc_offset > 0 ? '-' : '+',
abs(utc_offset / 3600), abs(utc_offset / 60),
abs(((utc_offset % 3600) / 60))); abs((utc_offset % 60)));
RETURN_NEW_STR(tmpstr); RETURN_NEW_STR(tmpstr);
} }
@ -3881,10 +3879,10 @@ PHP_FUNCTION(timezone_offset_get)
timelib_time_offset_dtor(offset); timelib_time_offset_dtor(offset);
break; break;
case TIMELIB_ZONETYPE_OFFSET: case TIMELIB_ZONETYPE_OFFSET:
RETURN_LONG(tzobj->tzi.utc_offset); RETURN_LONG(tzobj->tzi.utc_offset * -60);
break; break;
case TIMELIB_ZONETYPE_ABBR: case TIMELIB_ZONETYPE_ABBR:
RETURN_LONG(tzobj->tzi.z.utc_offset + (tzobj->tzi.z.dst * 3600)); RETURN_LONG((tzobj->tzi.z.utc_offset - (tzobj->tzi.z.dst*60)) * -60);
break; break;
} }
} }

View file

@ -8,7 +8,7 @@ date_default_timezone_set('UTC');
echo "Done\n"; echo "Done\n";
?> ?>
--EXPECTF-- --EXPECTF--
array(5) { array(6) {
[0]=> [0]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
@ -16,7 +16,7 @@ array(5) {
["offset"]=> ["offset"]=>
int(0) int(0)
["timezone_id"]=> ["timezone_id"]=>
string(13) "Etc/Universal" string(16) "Antarctica/Troll"
} }
[1]=> [1]=>
array(3) { array(3) {
@ -25,7 +25,7 @@ array(5) {
["offset"]=> ["offset"]=>
int(0) int(0)
["timezone_id"]=> ["timezone_id"]=>
string(7) "Etc/UTC" string(13) "Etc/Universal"
} }
[2]=> [2]=>
array(3) { array(3) {
@ -34,7 +34,7 @@ array(5) {
["offset"]=> ["offset"]=>
int(0) int(0)
["timezone_id"]=> ["timezone_id"]=>
string(8) "Etc/Zulu" string(7) "Etc/UTC"
} }
[3]=> [3]=>
array(3) { array(3) {
@ -43,7 +43,7 @@ array(5) {
["offset"]=> ["offset"]=>
int(0) int(0)
["timezone_id"]=> ["timezone_id"]=>
string(3) "UTC" string(8) "Etc/Zulu"
} }
[4]=> [4]=>
array(3) { array(3) {
@ -54,5 +54,14 @@ array(5) {
["timezone_id"]=> ["timezone_id"]=>
string(3) "UTC" string(3) "UTC"
} }
[5]=>
array(3) {
["dst"]=>
bool(false)
["offset"]=>
int(0)
["timezone_id"]=>
string(3) "UTC"
}
} }
Done Done

View file

@ -53,9 +53,30 @@ Array
[comments] => %s [comments] => %s
) )
Array Array
(
[country_code] => %s
[latitude] => %f
[longitude] => %f
[comments] =>
)
Array
( (
[country_code] => %s [country_code] => %s
[latitude] => %f [latitude] => %f
[longitude] => %f [longitude] => %f
[comments] => %s [comments] => %s
) )
Array
(
[country_code] => %s
[latitude] => %f
[longitude] => %f
[comments] => %s
)
Array
(
[country_code] => %s
[latitude] => %f
[longitude] => %f
[comments] =>
)

View file

@ -29,15 +29,15 @@ string(5) "array"
int(%d) int(%d)
-- Format a sample entry -- -- Format a sample entry --
array(12) { array(11) {
[0]=> [0]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(true)
["offset"]=> ["offset"]=>
int(32400) int(-14400)
["timezone_id"]=> ["timezone_id"]=>
string(18) "Australia/Adelaide" string(18) "America/Porto_Acre"
} }
[1]=> [1]=>
array(3) { array(3) {
@ -51,47 +51,47 @@ array(12) {
[2]=> [2]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(true)
["offset"]=> ["offset"]=>
int(32400) int(-14400)
["timezone_id"]=> ["timezone_id"]=>
string(21) "Australia/Broken_Hill" string(16) "America/Eirunepe"
} }
[3]=> [3]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(true)
["offset"]=> ["offset"]=>
int(32400) int(-14400)
["timezone_id"]=> ["timezone_id"]=>
string(16) "Australia/Darwin" string(18) "America/Rio_Branco"
} }
[4]=> [4]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(true)
["offset"]=> ["offset"]=>
int(32400) int(-14400)
["timezone_id"]=> ["timezone_id"]=>
string(15) "Australia/North" string(11) "Brazil/Acre"
} }
[5]=> [5]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(false)
["offset"]=> ["offset"]=>
int(32400) int(34200)
["timezone_id"]=> ["timezone_id"]=>
string(15) "Australia/South" string(13) "Asia/Jayapura"
} }
[6]=> [6]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(false)
["offset"]=> ["offset"]=>
int(32400) int(34200)
["timezone_id"]=> ["timezone_id"]=>
string(20) "Australia/Yancowinna" string(21) "Australia/Broken_Hill"
} }
[7]=> [7]=>
array(3) { array(3) {
@ -100,7 +100,7 @@ array(12) {
["offset"]=> ["offset"]=>
int(34200) int(34200)
["timezone_id"]=> ["timezone_id"]=>
string(21) "Australia/Broken_Hill" string(16) "Australia/Darwin"
} }
[8]=> [8]=>
array(3) { array(3) {
@ -109,18 +109,9 @@ array(12) {
["offset"]=> ["offset"]=>
int(34200) int(34200)
["timezone_id"]=> ["timezone_id"]=>
string(16) "Australia/Darwin" string(15) "Australia/North"
} }
[9]=> [9]=>
array(3) {
["dst"]=>
bool(false)
["offset"]=>
int(34200)
["timezone_id"]=>
string(15) "Australia/North"
}
[10]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(false)
@ -129,7 +120,7 @@ array(12) {
["timezone_id"]=> ["timezone_id"]=>
string(15) "Australia/South" string(15) "Australia/South"
} }
[11]=> [10]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(false)

View file

@ -42,7 +42,7 @@ array(16) {
["zone_type"]=> ["zone_type"]=>
int(2) int(2)
["zone"]=> ["zone"]=>
int(3600) int(-60)
["is_dst"]=> ["is_dst"]=>
bool(false) bool(false)
["tz_abbr"]=> ["tz_abbr"]=>

View file

@ -40,20 +40,20 @@ echo "\n";
NULL NULL
NULL NULL
int(3600) int(-60)
string(1) "A" string(1) "A"
int(3600) int(-60)
string(1) "A" string(1) "A"
int(3600) int(-60)
string(1) "A" string(1) "A"
int(3600) int(-60)
string(1) "A" string(1) "A"
int(3600) int(-60)
string(1) "A" string(1) "A"
int(3600) int(-60)
string(1) "A" string(1) "A"

View file

@ -5,7 +5,7 @@ date.timezone=Asia/Singapore
--FILE-- --FILE--
<?php <?php
print strtotime('2008-05-23 00:00:00 +08'); print strtotime('2008-05-23 00:00:00 SGT');
print "\n"; print "\n";
print strtotime('2008-05-23 00:00:00'); print strtotime('2008-05-23 00:00:00');

View file

@ -7,10 +7,10 @@ date_default_timezone_set('UTC');
$earlyDate1 = DateTime::createFromFormat('U.u', '1.8642')->modify('-5 seconds'); $earlyDate1 = DateTime::createFromFormat('U.u', '1.8642')->modify('-5 seconds');
$earlyDate2 = DateTime::createFromFormat('U.u', '1.2768')->modify('-5 seconds'); $earlyDate2 = DateTime::createFromFormat('U.u', '1.2768')->modify('-5 seconds');
$earlyDate3 = DateTime::createFromFormat('U.u', '1.2768')->modify('-5 seconds'); $earlyDate3 = DateTime::createFromFormat('U.u', '1.2768')->modify('-5 seconds');
// var_dump($earlyDate1, $earlyDate2, $earlyDate3);
var_dump($earlyDate1 == $earlyDate2); var_dump($earlyDate1 == $earlyDate2);
var_dump($earlyDate1 > $earlyDate2); var_dump($earlyDate1 < $earlyDate2);
var_dump($earlyDate2 < $earlyDate1); var_dump($earlyDate2 > $earlyDate1);
var_dump($earlyDate2 == $earlyDate3); var_dump($earlyDate2 == $earlyDate3);
--EXPECT-- --EXPECT--
bool(false) bool(false)

View file

@ -104,7 +104,7 @@ array(15) {
["zone_type"]=> ["zone_type"]=>
int(1) int(1)
["zone"]=> ["zone"]=>
int(-43200) int(720)
["is_dst"]=> ["is_dst"]=>
bool(false) bool(false)
} }
@ -228,7 +228,7 @@ array(15) {
["zone_type"]=> ["zone_type"]=>
int(1) int(1)
["zone"]=> ["zone"]=>
int(-10800) int(180)
["is_dst"]=> ["is_dst"]=>
bool(false) bool(false)
} }

View file

@ -10,22 +10,22 @@ echo "Done\n";
--EXPECTF-- --EXPECTF--
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165897761) int(1165897782)
["sunset"]=> ["sunset"]=>
int(1165934160) int(1165934168)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165896156) int(1165896176)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165935765) int(1165935773)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165894334) int(1165894353)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165937588) int(1165937597)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165892551) int(1165892570)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165939371) int(1165939380)
} }
Done Done

View file

@ -11,13 +11,13 @@ foreach ($sun_info as $key => $elem )
echo "Done\n"; echo "Done\n";
?> ?>
--EXPECTF-- --EXPECTF--
2007-04-13 06:13:31 CEST sunrise 2007-04-13 06:12:19 CEST sunrise
2007-04-13 20:30:51 CEST sunset 2007-04-13 20:31:50 CEST sunset
2007-04-13 13:22:11 CEST transit 2007-04-13 13:22:05 CEST transit
2007-04-13 05:29:22 CEST civil_twilight_begin 2007-04-13 05:28:03 CEST civil_twilight_begin
2007-04-13 21:15:00 CEST civil_twilight_end 2007-04-13 21:16:06 CEST civil_twilight_end
2007-04-13 04:31:43 CEST nautical_twilight_begin 2007-04-13 04:30:08 CEST nautical_twilight_begin
2007-04-13 22:12:39 CEST nautical_twilight_end 2007-04-13 22:14:01 CEST nautical_twilight_end
2007-04-13 03:17:01 CEST astronomical_twilight_begin 2007-04-13 03:14:36 CEST astronomical_twilight_begin
2007-04-13 23:27:21 CEST astronomical_twilight_end 2007-04-13 23:29:33 CEST astronomical_twilight_end
Done Done

View file

@ -84,331 +84,331 @@ foreach($inputs as $input) {
-- Iteration 1 -- -- Iteration 1 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 2 -- -- Iteration 2 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 3 -- -- Iteration 3 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 4 -- -- Iteration 4 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(-69672) int(-69665)
["sunset"]=> ["sunset"]=>
int(-33281) int(-33260)
["transit"]=> ["transit"]=>
int(-51476) int(-51462)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(-71277) int(-71269)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(-31675) int(-31655)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(-73100) int(-73092)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(-29852) int(-29832)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(-74883) int(-74874)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(-28069) int(-28050)
} }
-- Iteration 5 -- -- Iteration 5 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 6 -- -- Iteration 6 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(-69672) int(-69665)
["sunset"]=> ["sunset"]=>
int(-33281) int(-33260)
["transit"]=> ["transit"]=>
int(-51476) int(-51462)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(-71277) int(-71269)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(-31675) int(-31655)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(-73100) int(-73092)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(-29852) int(-29832)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(-74883) int(-74874)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(-28069) int(-28050)
} }
-- Iteration 7 -- -- Iteration 7 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1226368) int(1226363)
["sunset"]=> ["sunset"]=>
int(1263442) int(1263468)
["transit"]=> ["transit"]=>
int(1244905) int(1244916)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1224792) int(1224788)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1265019) int(1265044)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1222996) int(1222993)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1266815) int(1266839)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1221234) int(1221233)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1268576) int(1268599)
} }
-- Iteration 8 -- -- Iteration 8 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 9 -- -- Iteration 9 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 10 -- -- Iteration 10 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 11 -- -- Iteration 11 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 12 -- -- Iteration 12 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 13 -- -- Iteration 13 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 14 -- -- Iteration 14 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 15 -- -- Iteration 15 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 16 -- -- Iteration 16 --
@ -444,49 +444,49 @@ bool(false)
-- Iteration 22 -- -- Iteration 22 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 23 -- -- Iteration 23 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(16742) int(16748)
["sunset"]=> ["sunset"]=>
int(53161) int(53182)
["transit"]=> ["transit"]=>
int(34951) int(34965)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(15138) int(15145)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(54765) int(54786)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(13316) int(13324)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(56587) int(56607)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(11534) int(11542)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(58369) int(58389)
} }
-- Iteration 24 -- -- Iteration 24 --
Warning: date_sun_info() expects parameter 1 to be integer, resource given in %s on line %d Warning: date_sun_info() expects parameter 1 to be integer, resource given in %s on line %d
bool(false) bool(false)
===Done=== ===Done===

View file

@ -84,45 +84,45 @@ foreach($inputs as $input) {
-- Iteration 1 -- -- Iteration 1 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894138) int(1165894152)
["sunset"]=> ["sunset"]=>
int(1165937784) int(1165937798)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165892795) int(1165892809)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165939127) int(1165939141)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165891226) int(1165891239)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165940696) int(1165940710)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165889650) int(1165889663)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165942271) int(1165942287)
} }
-- Iteration 2 -- -- Iteration 2 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894240) int(1165894254)
["sunset"]=> ["sunset"]=>
int(1165937681) int(1165937695)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165892898) int(1165892911)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165939024) int(1165939038)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165891330) int(1165891344)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165940591) int(1165940606)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165889758) int(1165889771)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165942164) int(1165942179)
} }
-- Iteration 3 -- -- Iteration 3 --
@ -132,283 +132,283 @@ array(9) {
["sunset"]=> ["sunset"]=>
bool(true) bool(true)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
bool(true) bool(true)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
bool(true) bool(true)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165883368) int(1165883331)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165948554) int(1165948619)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165890281) int(1165890260)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165941641) int(1165941690)
} }
-- Iteration 4 -- -- Iteration 4 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894072) int(1165894085)
["sunset"]=> ["sunset"]=>
int(1165937850) int(1165937865)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165895418) int(1165895431)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165936504) int(1165936519)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165896984) int(1165896998)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165934938) int(1165934952)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165898549) int(1165898564)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165933372) int(1165933386)
} }
-- Iteration 5 -- -- Iteration 5 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165895221) int(1165895237)
["sunset"]=> ["sunset"]=>
int(1165936701) int(1165936713)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165893858) int(1165893873)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165938064) int(1165938077)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165892278) int(1165892293)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165939643) int(1165939656)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165890706) int(1165890721)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165941215) int(1165941229)
} }
-- Iteration 6 -- -- Iteration 6 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165893046) int(1165893058)
["sunset"]=> ["sunset"]=>
int(1165938875) int(1165938891)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165891669) int(1165891680)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165940253) int(1165940269)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165890044) int(1165890055)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165941878) int(1165941895)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165888392) int(1165888402)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165943530) int(1165943548)
} }
-- Iteration 7 -- -- Iteration 7 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894138) int(1165894152)
["sunset"]=> ["sunset"]=>
int(1165937784) int(1165937798)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165892795) int(1165892809)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165939127) int(1165939141)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165891226) int(1165891239)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165940696) int(1165940710)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165889650) int(1165889663)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165942271) int(1165942287)
} }
-- Iteration 8 -- -- Iteration 8 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894138) int(1165894152)
["sunset"]=> ["sunset"]=>
int(1165937784) int(1165937798)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165892795) int(1165892809)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165939127) int(1165939141)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165891226) int(1165891239)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165940696) int(1165940710)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165889650) int(1165889663)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165942271) int(1165942287)
} }
-- Iteration 9 -- -- Iteration 9 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894189) int(1165894203)
["sunset"]=> ["sunset"]=>
int(1165937733) int(1165937747)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165892846) int(1165892860)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165939075) int(1165939090)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165891278) int(1165891292)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165940643) int(1165940658)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165889704) int(1165889717)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165942217) int(1165942233)
} }
-- Iteration 10 -- -- Iteration 10 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894138) int(1165894152)
["sunset"]=> ["sunset"]=>
int(1165937784) int(1165937798)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165892795) int(1165892809)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165939127) int(1165939141)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165891226) int(1165891239)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165940696) int(1165940710)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165889650) int(1165889663)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165942271) int(1165942287)
} }
-- Iteration 11 -- -- Iteration 11 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894138) int(1165894152)
["sunset"]=> ["sunset"]=>
int(1165937784) int(1165937798)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165892795) int(1165892809)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165939127) int(1165939141)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165891226) int(1165891239)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165940696) int(1165940710)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165889650) int(1165889663)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165942271) int(1165942287)
} }
-- Iteration 12 -- -- Iteration 12 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894240) int(1165894254)
["sunset"]=> ["sunset"]=>
int(1165937681) int(1165937695)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165892898) int(1165892911)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165939024) int(1165939038)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165891330) int(1165891344)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165940591) int(1165940606)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165889758) int(1165889771)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165942164) int(1165942179)
} }
-- Iteration 13 -- -- Iteration 13 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894138) int(1165894152)
["sunset"]=> ["sunset"]=>
int(1165937784) int(1165937798)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165892795) int(1165892809)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165939127) int(1165939141)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165891226) int(1165891239)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165940696) int(1165940710)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165889650) int(1165889663)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165942271) int(1165942287)
} }
-- Iteration 14 -- -- Iteration 14 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894240) int(1165894254)
["sunset"]=> ["sunset"]=>
int(1165937681) int(1165937695)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165892898) int(1165892911)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165939024) int(1165939038)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165891330) int(1165891344)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165940591) int(1165940606)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165889758) int(1165889771)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165942164) int(1165942179)
} }
-- Iteration 15 -- -- Iteration 15 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894138) int(1165894152)
["sunset"]=> ["sunset"]=>
int(1165937784) int(1165937798)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165892795) int(1165892809)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165939127) int(1165939141)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165891226) int(1165891239)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165940696) int(1165940710)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165889650) int(1165889663)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165942271) int(1165942287)
} }
-- Iteration 16 -- -- Iteration 16 --
@ -444,45 +444,45 @@ bool(false)
-- Iteration 22 -- -- Iteration 22 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894138) int(1165894152)
["sunset"]=> ["sunset"]=>
int(1165937784) int(1165937798)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165892795) int(1165892809)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165939127) int(1165939141)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165891226) int(1165891239)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165940696) int(1165940710)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165889650) int(1165889663)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165942271) int(1165942287)
} }
-- Iteration 23 -- -- Iteration 23 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165894138) int(1165894152)
["sunset"]=> ["sunset"]=>
int(1165937784) int(1165937798)
["transit"]=> ["transit"]=>
int(1165915961) int(1165915975)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165892795) int(1165892809)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165939127) int(1165939141)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165891226) int(1165891239)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165940696) int(1165940710)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165889650) int(1165889663)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165942271) int(1165942287)
} }
-- Iteration 24 -- -- Iteration 24 --

View file

@ -85,331 +85,331 @@ foreach($inputs as $input) {
-- Iteration 1 -- -- Iteration 1 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165906221) int(1165906242)
["sunset"]=> ["sunset"]=>
int(1165942618) int(1165942625)
["transit"]=> ["transit"]=>
int(1165924420) int(1165924434)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165904616) int(1165904636)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165944223) int(1165944231)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165902793) int(1165902813)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165946046) int(1165946054)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165901011) int(1165901030)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165947828) int(1165947838)
} }
-- Iteration 2 -- -- Iteration 2 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165905981) int(1165906002)
["sunset"]=> ["sunset"]=>
int(1165942378) int(1165942385)
["transit"]=> ["transit"]=>
int(1165924179) int(1165924194)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165904376) int(1165904396)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165943983) int(1165943991)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165902553) int(1165902573)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165945806) int(1165945814)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165900771) int(1165900789)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165947588) int(1165947598)
} }
-- Iteration 3 -- -- Iteration 3 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165879309) int(1165879335)
["sunset"]=> ["sunset"]=>
int(1165917937) int(1165917916)
["transit"]=> ["transit"]=>
int(1165898623) int(1165898625)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165877787) int(1165877811)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165919460) int(1165919440)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165876041) int(1165876064)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165921205) int(1165921187)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165874319) int(1165874341)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165922928) int(1165922910)
} }
-- Iteration 4 -- -- Iteration 4 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165864467) int(1165864483)
["sunset"]=> ["sunset"]=>
int(1165900749) int(1165900762)
["transit"]=> ["transit"]=>
int(1165882608) int(1165882623)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165862856) int(1165862873)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165902359) int(1165902372)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165861029) int(1165861045)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165904187) int(1165904200)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165859242) int(1165859259)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165905973) int(1165905987)
} }
-- Iteration 5 -- -- Iteration 5 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165903700) int(1165903721)
["sunset"]=> ["sunset"]=>
int(1165940097) int(1165940105)
["transit"]=> ["transit"]=>
int(1165921899) int(1165921913)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165902095) int(1165902115)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165941702) int(1165941711)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165900272) int(1165900292)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165943525) int(1165943534)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165898490) int(1165898508)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165945308) int(1165945317)
} }
-- Iteration 6 -- -- Iteration 6 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165908743) int(1165908763)
["sunset"]=> ["sunset"]=>
int(1165945138) int(1165945146)
["transit"]=> ["transit"]=>
int(1165926940) int(1165926954)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165907137) int(1165907157)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165946743) int(1165946752)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165905315) int(1165905334)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165948566) int(1165948575)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165903532) int(1165903551)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165950349) int(1165950358)
} }
-- Iteration 7 -- -- Iteration 7 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165920008) int(1165919856)
["sunset"]=> ["sunset"]=>
int(1165970177) int(1165969985)
["transit"]=> ["transit"]=>
int(1165945092) int(1165944920)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165918353) int(1165918203)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165971832) int(1165971638)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165916371) int(1165916223)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165973814) int(1165973617)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165914258) int(1165914116)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165975927) int(1165975725)
} }
-- Iteration 8 -- -- Iteration 8 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165906221) int(1165906242)
["sunset"]=> ["sunset"]=>
int(1165942618) int(1165942625)
["transit"]=> ["transit"]=>
int(1165924420) int(1165924434)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165904616) int(1165904636)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165944223) int(1165944231)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165902793) int(1165902813)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165946046) int(1165946054)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165901011) int(1165901030)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165947828) int(1165947838)
} }
-- Iteration 9 -- -- Iteration 9 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165906101) int(1165906122)
["sunset"]=> ["sunset"]=>
int(1165942498) int(1165942505)
["transit"]=> ["transit"]=>
int(1165924300) int(1165924314)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165904496) int(1165904516)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165944103) int(1165944111)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165902673) int(1165902693)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165945926) int(1165945934)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165900891) int(1165900910)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165947708) int(1165947718)
} }
-- Iteration 10 -- -- Iteration 10 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165906221) int(1165906242)
["sunset"]=> ["sunset"]=>
int(1165942618) int(1165942625)
["transit"]=> ["transit"]=>
int(1165924420) int(1165924434)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165904616) int(1165904636)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165944223) int(1165944231)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165902793) int(1165902813)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165946046) int(1165946054)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165901011) int(1165901030)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165947828) int(1165947838)
} }
-- Iteration 11 -- -- Iteration 11 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165906221) int(1165906242)
["sunset"]=> ["sunset"]=>
int(1165942618) int(1165942625)
["transit"]=> ["transit"]=>
int(1165924420) int(1165924434)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165904616) int(1165904636)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165944223) int(1165944231)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165902793) int(1165902813)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165946046) int(1165946054)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165901011) int(1165901030)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165947828) int(1165947838)
} }
-- Iteration 12 -- -- Iteration 12 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165905981) int(1165906002)
["sunset"]=> ["sunset"]=>
int(1165942378) int(1165942385)
["transit"]=> ["transit"]=>
int(1165924179) int(1165924194)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165904376) int(1165904396)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165943983) int(1165943991)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165902553) int(1165902573)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165945806) int(1165945814)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165900771) int(1165900789)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165947588) int(1165947598)
} }
-- Iteration 13 -- -- Iteration 13 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165906221) int(1165906242)
["sunset"]=> ["sunset"]=>
int(1165942618) int(1165942625)
["transit"]=> ["transit"]=>
int(1165924420) int(1165924434)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165904616) int(1165904636)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165944223) int(1165944231)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165902793) int(1165902813)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165946046) int(1165946054)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165901011) int(1165901030)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165947828) int(1165947838)
} }
-- Iteration 14 -- -- Iteration 14 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165905981) int(1165906002)
["sunset"]=> ["sunset"]=>
int(1165942378) int(1165942385)
["transit"]=> ["transit"]=>
int(1165924179) int(1165924194)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165904376) int(1165904396)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165943983) int(1165943991)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165902553) int(1165902573)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165945806) int(1165945814)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165900771) int(1165900789)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165947588) int(1165947598)
} }
-- Iteration 15 -- -- Iteration 15 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165906221) int(1165906242)
["sunset"]=> ["sunset"]=>
int(1165942618) int(1165942625)
["transit"]=> ["transit"]=>
int(1165924420) int(1165924434)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165904616) int(1165904636)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165944223) int(1165944231)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165902793) int(1165902813)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165946046) int(1165946054)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165901011) int(1165901030)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165947828) int(1165947838)
} }
-- Iteration 16 -- -- Iteration 16 --
@ -445,45 +445,45 @@ bool(false)
-- Iteration 22 -- -- Iteration 22 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165906221) int(1165906242)
["sunset"]=> ["sunset"]=>
int(1165942618) int(1165942625)
["transit"]=> ["transit"]=>
int(1165924420) int(1165924434)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165904616) int(1165904636)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165944223) int(1165944231)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165902793) int(1165902813)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165946046) int(1165946054)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165901011) int(1165901030)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165947828) int(1165947838)
} }
-- Iteration 23 -- -- Iteration 23 --
array(9) { array(9) {
["sunrise"]=> ["sunrise"]=>
int(1165906221) int(1165906242)
["sunset"]=> ["sunset"]=>
int(1165942618) int(1165942625)
["transit"]=> ["transit"]=>
int(1165924420) int(1165924434)
["civil_twilight_begin"]=> ["civil_twilight_begin"]=>
int(1165904616) int(1165904636)
["civil_twilight_end"]=> ["civil_twilight_end"]=>
int(1165944223) int(1165944231)
["nautical_twilight_begin"]=> ["nautical_twilight_begin"]=>
int(1165902793) int(1165902813)
["nautical_twilight_end"]=> ["nautical_twilight_end"]=>
int(1165946046) int(1165946054)
["astronomical_twilight_begin"]=> ["astronomical_twilight_begin"]=>
int(1165901011) int(1165901030)
["astronomical_twilight_end"]=> ["astronomical_twilight_end"]=>
int(1165947828) int(1165947838)
} }
-- Iteration 24 -- -- Iteration 24 --

View file

@ -109,38 +109,38 @@ foreach($inputs as $key =>$value) {
--int 0-- --int 0--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--int 1-- --int 1--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--int 12345-- --int 12345--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--int -12345-- --int -12345--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--float 10.5-- --float 10.5--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--float -10.5-- --float -10.5--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--float .5-- --float .5--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--empty array-- --empty array--
@ -188,33 +188,33 @@ bool(false)
--uppercase NULL-- --uppercase NULL--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--lowercase null-- --lowercase null--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--lowercase true-- --lowercase true--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--lowercase false-- --lowercase false--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--uppercase TRUE-- --uppercase TRUE--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--uppercase FALSE-- --uppercase FALSE--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--empty string DQ-- --empty string DQ--
@ -306,11 +306,11 @@ bool(false)
--undefined var-- --undefined var--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
--unset var-- --unset var--
string(5) "08:56" string(5) "08:56"
float(8.943%d) float(8.944%d)
int(28596) int(28599)
===DONE=== ===DONE===

View file

@ -103,12 +103,12 @@ foreach($inputs as $key =>$value) {
--int 0-- --int 0--
string(5) "01:10" string(5) "01:10"
float(1.174%d) float(1.174%d)
int(1218177629) int(1218177627)
--int 1-- --int 1--
string(5) "01:09" string(5) "01:09"
float(1.155%d) float(1.155%d)
int(1218177560) int(1218177558)
--int 12345-- --int 12345--
bool(false) bool(false)
@ -167,32 +167,32 @@ bool(false)
--uppercase NULL-- --uppercase NULL--
string(5) "01:10" string(5) "01:10"
float(1.174%d) float(1.174%d)
int(1218177629) int(1218177627)
--lowercase null-- --lowercase null--
string(5) "01:10" string(5) "01:10"
float(1.174%d) float(1.174%d)
int(1218177629) int(1218177627)
--lowercase true-- --lowercase true--
string(5) "01:09" string(5) "01:09"
float(1.155%d) float(1.155%d)
int(1218177560) int(1218177558)
--lowercase false-- --lowercase false--
string(5) "01:10" string(5) "01:10"
float(1.174%d) float(1.174%d)
int(1218177629) int(1218177627)
--uppercase TRUE-- --uppercase TRUE--
string(5) "01:09" string(5) "01:09"
float(1.155%d) float(1.155%d)
int(1218177560) int(1218177558)
--uppercase FALSE-- --uppercase FALSE--
string(5) "01:10" string(5) "01:10"
float(1.174%d) float(1.174%d)
int(1218177629) int(1218177627)
--empty string DQ-- --empty string DQ--
@ -285,10 +285,10 @@ bool(false)
--undefined var-- --undefined var--
string(5) "01:10" string(5) "01:10"
float(1.174%d) float(1.174%d)
int(1218177629) int(1218177627)
--unset var-- --unset var--
string(5) "01:10" string(5) "01:10"
float(1.174%d) float(1.174%d)
int(1218177629) int(1218177627)
===DONE=== ===DONE===

View file

@ -103,24 +103,24 @@ foreach($inputs as $key =>$value) {
*** Testing date_sunrise() : usage variation *** *** Testing date_sunrise() : usage variation ***
--int 0-- --int 0--
string(5) "05:11" string(5) "05:12"
float(5.196%d) float(5.200%d)
int(1218172307) int(1218172321)
--int 1-- --int 1--
string(5) "05:07" string(5) "05:08"
float(5.129%d) float(5.133%d)
int(1218172067) int(1218172081)
--int 12345-- --int 12345--
string(5) "21:45" string(5) "21:45"
float(21.757%d) float(21.759%d)
int(1218145525) int(1218145534)
--int -12345-- --int -12345--
string(5) "12:41" string(5) "12:41"
float(12.694%d) float(12.698%d)
int(1218199301) int(1218199315)
--empty array-- --empty array--
@ -167,34 +167,34 @@ Warning: date_sunrise() expects parameter 4 to be float, array given in %s on li
bool(false) bool(false)
--uppercase NULL-- --uppercase NULL--
string(5) "05:11" string(5) "05:12"
float(5.196%d) float(5.200%d)
int(1218172307) int(1218172321)
--lowercase null-- --lowercase null--
string(5) "05:11" string(5) "05:12"
float(5.196%d) float(5.200%d)
int(1218172307) int(1218172321)
--lowercase true-- --lowercase true--
string(5) "05:07" string(5) "05:08"
float(5.129%d) float(5.133%d)
int(1218172067) int(1218172081)
--lowercase false-- --lowercase false--
string(5) "05:11" string(5) "05:12"
float(5.196%d) float(5.200%d)
int(1218172307) int(1218172321)
--uppercase TRUE-- --uppercase TRUE--
string(5) "05:07" string(5) "05:08"
float(5.129%d) float(5.133%d)
int(1218172067) int(1218172081)
--uppercase FALSE-- --uppercase FALSE--
string(5) "05:11" string(5) "05:12"
float(5.196%d) float(5.200%d)
int(1218172307) int(1218172321)
--empty string DQ-- --empty string DQ--
@ -285,12 +285,12 @@ Warning: date_sunrise() expects parameter 4 to be float, object given in %s on l
bool(false) bool(false)
--undefined var-- --undefined var--
string(5) "05:11" string(5) "05:12"
float(5.196%d) float(5.200%d)
int(1218172307) int(1218172321)
--unset var-- --unset var--
string(5) "05:11" string(5) "05:12"
float(5.196%d) float(5.200%d)
int(1218172307) int(1218172321)
===DONE=== ===DONE===

View file

@ -113,14 +113,14 @@ bool(false)
bool(false) bool(false)
--int 12345-- --int 12345--
string(5) "09:50" string(5) "09:51"
float(9.849%d) float(9.855%d)
int(1218169259) int(1218169278)
--int -12345-- --int -12345--
string(5) "09:54" string(5) "09:54"
float(9.904%d) float(9.9097820911118)
int(1218169455) int(1218169475)
--empty array-- --empty array--

View file

@ -102,24 +102,24 @@ foreach($inputs as $key =>$value) {
*** Testing date_sunrise() : usage variation *** *** Testing date_sunrise() : usage variation ***
--int 0-- --int 0--
string(5) "05:47" string(5) "05:48"
float(5.796%d) float(5.800%d)
int(1218174468) int(1218174483)
--int 1-- --int 1--
string(5) "06:47" string(5) "06:48"
float(6.796%d) float(6.800%d)
int(1218174468) int(1218174483)
--int 12345-- --int 12345--
string(5) "14:47" string(5) "14:48"
float(14.796%d) float(14.800%d)
int(1218174468) int(1218174483)
--int -12345-- --int -12345--
string(5) "12:47" string(5) "12:48"
float(12.796%d) float(12.800%d)
int(1218174468) int(1218174483)
--empty array-- --empty array--
@ -166,34 +166,34 @@ Warning: date_sunrise() expects parameter 6 to be float, array given in %s on li
bool(false) bool(false)
--uppercase NULL-- --uppercase NULL--
string(5) "05:47" string(5) "05:48"
float(5.796%d) float(5.800%d)
int(1218174468) int(1218174483)
--lowercase null-- --lowercase null--
string(5) "05:47" string(5) "05:48"
float(5.796%d) float(5.800%d)
int(1218174468) int(1218174483)
--lowercase true-- --lowercase true--
string(5) "06:47" string(5) "06:48"
float(6.796%d) float(6.800%d)
int(1218174468) int(1218174483)
--lowercase false-- --lowercase false--
string(5) "05:47" string(5) "05:48"
float(5.796%d) float(5.800%d)
int(1218174468) int(1218174483)
--uppercase TRUE-- --uppercase TRUE--
string(5) "06:47" string(5) "06:48"
float(6.796%d) float(6.800%d)
int(1218174468) int(1218174483)
--uppercase FALSE-- --uppercase FALSE--
string(5) "05:47" string(5) "05:48"
float(5.796%d) float(5.800%d)
int(1218174468) int(1218174483)
--empty string DQ-- --empty string DQ--
@ -284,12 +284,12 @@ Warning: date_sunrise() expects parameter 6 to be float, object given in %s on l
bool(false) bool(false)
--undefined var-- --undefined var--
string(5) "05:47" string(5) "05:48"
float(5.796%d) float(5.800%d)
int(1218174468) int(1218174483)
--unset var-- --unset var--
string(5) "05:47" string(5) "05:48"
float(5.796%d) float(5.800%d)
int(1218174468) int(1218174483)
===DONE=== ===DONE===

View file

@ -36,15 +36,15 @@ foreach($inputs as $timezone => $value) {
===DONE=== ===DONE===
--EXPECTF-- --EXPECTF--
*** Testing date_sunrise() : usage variation *** *** Testing date_sunrise() : usage variation ***
string(5) "06:42"
string(5) "06:41" string(5) "06:41"
string(5) "05:07" string(5) "06:41"
string(5) "05:09" string(5) "05:09"
string(5) "05:58" string(5) "05:11"
string(5) "05:59" string(5) "05:59"
string(5) "07:31" string(5) "06:00"
string(5) "07:30" string(5) "07:30"
string(5) "05:52" string(5) "07:29"
string(5) "05:53"
string(5) "05:53" string(5) "05:53"
string(5) "05:59" string(5) "05:59"
string(5) "06:01" string(5) "06:01"

View file

@ -109,38 +109,38 @@ foreach($inputs as $key =>$value) {
--int 0-- --int 0--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--int 1-- --int 1--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--int 12345-- --int 12345--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--int -12345-- --int -12345--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--float 10.5-- --float 10.5--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--float -10.5-- --float -10.5--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--float .5-- --float .5--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--empty array-- --empty array--
@ -188,33 +188,33 @@ bool(false)
--uppercase NULL-- --uppercase NULL--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--lowercase null-- --lowercase null--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--lowercase true-- --lowercase true--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--lowercase false-- --lowercase false--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--uppercase TRUE-- --uppercase TRUE--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--uppercase FALSE-- --uppercase FALSE--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--empty string DQ-- --empty string DQ--
@ -306,11 +306,11 @@ bool(false)
--undefined var-- --undefined var--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
--unset var-- --unset var--
string(5) "18:22" string(5) "18:22"
float(18.373%d) float(18.377%d)
int(62545) int(62558)
===DONE=== ===DONE===

View file

@ -105,13 +105,13 @@ foreach($inputs as $key =>$value) {
--int 0-- --int 0--
string(5) "17:43" string(5) "17:43"
float(17.731%d) float(17.730%d)
int(1218197632) int(1218197630)
--int 1-- --int 1--
string(5) "17:45" string(5) "17:44"
float(17.750%d) float(17.749%d)
int(1218197701) int(1218197698)
--int 12345-- --int 12345--
bool(false) bool(false)
@ -169,33 +169,33 @@ bool(false)
--uppercase NULL-- --uppercase NULL--
string(5) "17:43" string(5) "17:43"
float(17.731%d) float(17.730%d)
int(1218197632) int(1218197630)
--lowercase null-- --lowercase null--
string(5) "17:43" string(5) "17:43"
float(17.731%d) float(17.730%d)
int(1218197632) int(1218197630)
--lowercase true-- --lowercase true--
string(5) "17:45" string(5) "17:44"
float(17.750%d) float(17.749%d)
int(1218197701) int(1218197698)
--lowercase false-- --lowercase false--
string(5) "17:43" string(5) "17:43"
float(17.731%d) float(17.730%d)
int(1218197632) int(1218197630)
--uppercase TRUE-- --uppercase TRUE--
string(5) "17:45" string(5) "17:44"
float(17.750%d) float(17.749%d)
int(1218197701) int(1218197698)
--uppercase FALSE-- --uppercase FALSE--
string(5) "17:43" string(5) "17:43"
float(17.731%d) float(17.730%d)
int(1218197632) int(1218197630)
--empty string DQ-- --empty string DQ--
@ -287,11 +287,11 @@ bool(false)
--undefined var-- --undefined var--
string(5) "17:43" string(5) "17:43"
float(17.731%d) float(17.730%d)
int(1218197632) int(1218197630)
--unset var-- --unset var--
string(5) "17:43" string(5) "17:43"
float(17.731%d) float(17.730%d)
int(1218197632) int(1218197630)
===DONE=== ===DONE===

View file

@ -104,13 +104,13 @@ foreach($inputs as $key =>$value) {
--int 0-- --int 0--
string(5) "00:03" string(5) "00:03"
float(0.062%d) float(0.059%d)
int(1218220425) int(1218220414)
--int 1-- --int 1--
string(5) "23:59" string(5) "23:59"
float(23.995%d) float(23.992%d)
int(1218220185) int(1218220174)
--int 12345-- --int 12345--
string(5) "17:15" string(5) "17:15"
@ -118,9 +118,9 @@ float(17.259%d)
int(1218195932) int(1218195932)
--int -12345-- --int -12345--
string(5) "12:19" string(5) "12:18"
float(12.319%d) float(12.316%d)
int(1218178151) int(1218178138)
--empty array-- --empty array--
@ -168,33 +168,33 @@ bool(false)
--uppercase NULL-- --uppercase NULL--
string(5) "00:03" string(5) "00:03"
float(0.062%d) float(0.059%d)
int(1218220425) int(1218220414)
--lowercase null-- --lowercase null--
string(5) "00:03" string(5) "00:03"
float(0.062%d) float(0.059%d)
int(1218220425) int(1218220414)
--lowercase true-- --lowercase true--
string(5) "23:59" string(5) "23:59"
float(23.995%d) float(23.992%d)
int(1218220185) int(1218220174)
--lowercase false-- --lowercase false--
string(5) "00:03" string(5) "00:03"
float(0.062%d) float(0.059%d)
int(1218220425) int(1218220414)
--uppercase TRUE-- --uppercase TRUE--
string(5) "23:59" string(5) "23:59"
float(23.995%d) float(23.992%d)
int(1218220185) int(1218220174)
--uppercase FALSE-- --uppercase FALSE--
string(5) "00:03" string(5) "00:03"
float(0.062%d) float(0.059%d)
int(1218220425) int(1218220414)
--empty string DQ-- --empty string DQ--
@ -286,11 +286,11 @@ bool(false)
--undefined var-- --undefined var--
string(5) "00:03" string(5) "00:03"
float(0.062%d) float(0.059%d)
int(1218220425) int(1218220414)
--unset var-- --unset var--
string(5) "00:03" string(5) "00:03"
float(0.062%d) float(0.059%d)
int(1218220425) int(1218220414)
===DONE=== ===DONE===

View file

@ -114,8 +114,8 @@ bool(false)
--int 12345-- --int 12345--
string(5) "19:20" string(5) "19:20"
float(19.343%d) float(19.340%d)
int(1218203437) int(1218203424)
--int -12345-- --int -12345--
bool(false) bool(false)

View file

@ -103,24 +103,24 @@ foreach($inputs as $key =>$value) {
*** Testing date_sunset() : usage variation *** *** Testing date_sunset() : usage variation ***
--int 0-- --int 0--
string(5) "12:41" string(5) "12:40"
float(12.684%d) float(12.681%d)
int(1218199264) int(1218199253)
--int 1-- --int 1--
string(5) "13:41" string(5) "13:40"
float(13.684%d) float(13.681%d)
int(1218199264) int(1218199253)
--int 12345-- --int 12345--
string(5) "21:41" string(5) "21:40"
float(21.684%d) float(21.681%d)
int(1218199264) int(1218199253)
--int -12345-- --int -12345--
string(5) "19:41" string(5) "19:40"
float(19.684%d) float(19.681%d)
int(1218199264) int(1218199253)
--empty array-- --empty array--
@ -167,34 +167,34 @@ Warning: date_sunset() expects parameter 6 to be float, array given in %s on lin
bool(false) bool(false)
--uppercase NULL-- --uppercase NULL--
string(5) "12:41" string(5) "12:40"
float(12.684%d) float(12.681%d)
int(1218199264) int(1218199253)
--lowercase null-- --lowercase null--
string(5) "12:41" string(5) "12:40"
float(12.684%d) float(12.681%d)
int(1218199264) int(1218199253)
--lowercase true-- --lowercase true--
string(5) "13:41" string(5) "13:40"
float(13.684%d) float(13.681%d)
int(1218199264) int(1218199253)
--lowercase false-- --lowercase false--
string(5) "12:41" string(5) "12:40"
float(12.684%d) float(12.681%d)
int(1218199264) int(1218199253)
--uppercase TRUE-- --uppercase TRUE--
string(5) "13:41" string(5) "13:40"
float(13.684%d) float(13.681%d)
int(1218199264) int(1218199253)
--uppercase FALSE-- --uppercase FALSE--
string(5) "12:41" string(5) "12:40"
float(12.684%d) float(12.681%d)
int(1218199264) int(1218199253)
--empty string DQ-- --empty string DQ--
@ -285,12 +285,12 @@ Warning: date_sunset() expects parameter 6 to be float, object given in %s on li
bool(false) bool(false)
--undefined var-- --undefined var--
string(5) "12:41" string(5) "12:40"
float(12.684%d) float(12.681%d)
int(1218199264) int(1218199253)
--unset var-- --unset var--
string(5) "12:41" string(5) "12:40"
float(12.684%d) float(12.681%d)
int(1218199264) int(1218199253)
===DONE=== ===DONE===

View file

@ -42,24 +42,24 @@ string(5) "18:13"
string(5) "18:13" string(5) "18:13"
--US/Alaska-- --US/Alaska--
string(5) "21:02" string(5) "21:00"
string(5) "20:59" string(5) "20:57"
--America/Chicago-- --America/Chicago--
string(5) "19:52"
string(5) "19:51" string(5) "19:51"
string(5) "19:50"
--America/Montevideo-- --America/Montevideo--
string(5) "18:08" string(5) "18:08"
string(5) "18:08" string(5) "18:09"
--Africa/Casablanca-- --Africa/Casablanca--
string(5) "19:18"
string(5) "19:17" string(5) "19:17"
string(5) "19:16"
--Europe/Moscow-- --Europe/Moscow--
string(5) "21:10" string(5) "21:09"
string(5) "21:08" string(5) "21:07"
--Asia/Hong_Kong-- --Asia/Hong_Kong--
string(5) "18:55" string(5) "18:55"

View file

@ -16,27 +16,27 @@ for($a=1;$a<=12;$a++){
} }
?> ?>
--EXPECTF-- --EXPECTF--
1041395858 06:37 6.6274307083%d 1041395864 06:37 6.6290131458%d
1041432434 16:47 16.787476435%d 1041432452 16:47 16.792451114%d
1044073871 06:31 6.5198435465%d 1044073855 06:30 6.5154089279%d
1044112440 17:14 17.233560530%d 1044112463 17:14 17.239870289%d
1046491524 06:05 6.0901858662%d 1046491495 06:04 6.0822145033%d
1046533056 17:37 17.626724279%d 1046533075 17:37 17.632011035%d
1049167610 05:26 5.4473483216%d 1049167581 05:26 5.4394438111%d
1049212759 17:59 17.988854003%d 1049212774 17:59 17.993035729%d
1051757554 04:52 4.8761196793%d 1051757532 04:52 4.8701934126%d
1051805991 18:19 18.330987470%d 1051806007 18:20 18.335390508%d
1054434782 04:33 4.5506171719%d 1054434776 04:32 4.5489827182%d
1054485634 18:40 18.676282498%d 1054485647 18:40 18.679812949%d
1057026940 04:35 4.5946862151%d 1057026949 04:35 4.5971956372%d
1057078197 18:49 18.832651294%d 1057078197 18:49 18.832563396%d
1059706395 04:53 4.8875657219%d 1059706409 04:53 4.8916575089%d
1059755854 18:37 18.626282855%d 1059755837 18:37 18.621440704%d
1062385985 05:13 5.2182752537%d 1062385999 05:13 5.2220951121%d
1062432319 18:05 18.088728929%d 1062432291 18:04 18.080957168%d
1064979083 05:31 5.5233314120%d 1064979098 05:31 5.5273199215%d
1065021981 17:26 17.439368589%d 1065021952 17:25 17.431339135%d
1067658825 05:53 5.8959513887%d 1067658845 05:54 5.9016292870%d
1067698295 16:51 16.859972460%d 1067698274 16:51 16.853902453%d
1070252367 06:19 6.3241991396%d 1070252387 06:19 6.3299242689%d
1070289384 16:36 16.606870705%d 1070289382 16:36 16.606312600%d

View file

@ -26,18 +26,18 @@ var_dump( $abbr["acst"] );
--EXPECTF-- --EXPECTF--
*** Testing timezone_abbreviations_list() : basic functionality *** *** Testing timezone_abbreviations_list() : basic functionality ***
string(5) "array" string(5) "array"
int(142) int(%d)
-- Format a sample entry -- -- Format a sample entry --
array(12) { array(11) {
[0]=> [0]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(true)
["offset"]=> ["offset"]=>
int(32400) int(-14400)
["timezone_id"]=> ["timezone_id"]=>
string(18) "Australia/Adelaide" string(18) "America/Porto_Acre"
} }
[1]=> [1]=>
array(3) { array(3) {
@ -51,47 +51,47 @@ array(12) {
[2]=> [2]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(true)
["offset"]=> ["offset"]=>
int(32400) int(-14400)
["timezone_id"]=> ["timezone_id"]=>
string(21) "Australia/Broken_Hill" string(16) "America/Eirunepe"
} }
[3]=> [3]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(true)
["offset"]=> ["offset"]=>
int(32400) int(-14400)
["timezone_id"]=> ["timezone_id"]=>
string(16) "Australia/Darwin" string(18) "America/Rio_Branco"
} }
[4]=> [4]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(true)
["offset"]=> ["offset"]=>
int(32400) int(-14400)
["timezone_id"]=> ["timezone_id"]=>
string(15) "Australia/North" string(11) "Brazil/Acre"
} }
[5]=> [5]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(false)
["offset"]=> ["offset"]=>
int(32400) int(34200)
["timezone_id"]=> ["timezone_id"]=>
string(15) "Australia/South" string(13) "Asia/Jayapura"
} }
[6]=> [6]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(false)
["offset"]=> ["offset"]=>
int(32400) int(34200)
["timezone_id"]=> ["timezone_id"]=>
string(20) "Australia/Yancowinna" string(21) "Australia/Broken_Hill"
} }
[7]=> [7]=>
array(3) { array(3) {
@ -100,7 +100,7 @@ array(12) {
["offset"]=> ["offset"]=>
int(34200) int(34200)
["timezone_id"]=> ["timezone_id"]=>
string(21) "Australia/Broken_Hill" string(16) "Australia/Darwin"
} }
[8]=> [8]=>
array(3) { array(3) {
@ -109,18 +109,9 @@ array(12) {
["offset"]=> ["offset"]=>
int(34200) int(34200)
["timezone_id"]=> ["timezone_id"]=>
string(16) "Australia/Darwin" string(15) "Australia/North"
} }
[9]=> [9]=>
array(3) {
["dst"]=>
bool(false)
["offset"]=>
int(34200)
["timezone_id"]=>
string(15) "Australia/North"
}
[10]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(false)
@ -129,7 +120,7 @@ array(12) {
["timezone_id"]=> ["timezone_id"]=>
string(15) "Australia/South" string(15) "Australia/South"
} }
[11]=> [10]=>
array(3) { array(3) {
["dst"]=> ["dst"]=>
bool(false) bool(false)

View file

@ -24,6 +24,11 @@ var_dump( timezone_name_from_abbr("EDT") );
echo "-- Lookup with name and offset--\n"; echo "-- Lookup with name and offset--\n";
var_dump( timezone_name_from_abbr("ADT", -10800) ); var_dump( timezone_name_from_abbr("ADT", -10800) );
var_dump( timezone_name_from_abbr("ADT", 14400) ); var_dump( timezone_name_from_abbr("ADT", 14400) );
var_dump( timezone_name_from_abbr("AKTT", 14400) );
var_dump( timezone_name_from_abbr("aktt", 18000) );
var_dump( timezone_name_from_abbr("Aktt", 21600) );
var_dump( timezone_name_from_abbr("AMST", -10800) );
var_dump( timezone_name_from_abbr("amst", 180000) );
echo "-- Tests without valid name - uses gmtOffset and isdst to find match --\n"; echo "-- Tests without valid name - uses gmtOffset and isdst to find match --\n";
var_dump( timezone_name_from_abbr("", 3600, 1) ); var_dump( timezone_name_from_abbr("", 3600, 1) );
@ -46,7 +51,12 @@ string(13) "Europe/Berlin"
string(16) "America/New_York" string(16) "America/New_York"
-- Lookup with name and offset-- -- Lookup with name and offset--
string(15) "America/Halifax" string(15) "America/Halifax"
string(15) "America/Halifax" string(12) "Asia/Baghdad"
string(11) "Asia/Aqtobe"
string(11) "Asia/Aqtobe"
string(11) "Asia/Aqtobe"
string(17) "America/Boa_Vista"
string(12) "Asia/Yerevan"
-- Tests without valid name - uses gmtOffset and isdst to find match -- -- Tests without valid name - uses gmtOffset and isdst to find match --
string(13) "Europe/London" string(13) "Europe/London"
string(17) "America/Sao_Paulo" string(17) "America/Sao_Paulo"
@ -55,4 +65,4 @@ string(15) "America/Halifax"
-- Tests with invalid offsets -- -- Tests with invalid offsets --
bool(false) bool(false)
bool(false) bool(false)
===DONE=== ===DONE===

View file

@ -56,8 +56,8 @@ U_CFUNC TimeZone *timezone_convert_datetimezone(int type,
break; break;
case TIMELIB_ZONETYPE_OFFSET: { case TIMELIB_ZONETYPE_OFFSET: {
int offset_mins = is_datetime int offset_mins = is_datetime
? ((php_date_obj*)object)->time->z / 60 ? -((php_date_obj*)object)->time->z
: (int)((php_timezone_obj*)object)->tzi.utc_offset / 60, : -(int)((php_timezone_obj*)object)->tzi.utc_offset,
hours = offset_mins / 60, hours = offset_mins / 60,
minutes = offset_mins - hours * 60; minutes = offset_mins - hours * 60;
minutes *= minutes > 0 ? 1 : -1; minutes *= minutes > 0 ? 1 : -1;

View file

@ -83,8 +83,8 @@ U_CFUNC zval *timezone_convert_to_datetimezone(const TimeZone *timeZone,
* so we must mess with DateTimeZone structure ourselves */ * so we must mess with DateTimeZone structure ourselves */
tzobj->initialized = 1; tzobj->initialized = 1;
tzobj->type = TIMELIB_ZONETYPE_OFFSET; tzobj->type = TIMELIB_ZONETYPE_OFFSET;
//convert offset from milliseconds to seconds //convert offset from milliseconds to minutes
tzobj->tzi.utc_offset = timeZone->getRawOffset() / 1000; tzobj->tzi.utc_offset = -1 * timeZone->getRawOffset() / (60 * 1000);
} else { } else {
zend_string *u8str; zend_string *u8str;
/* Call the constructor! */ /* Call the constructor! */