summaryrefslogtreecommitdiff
path: root/ext/date/lib/timelib.c
diff options
context:
space:
mode:
authorLonny Kapelushnik <lonnyk@gmail.com>2013-01-14 23:03:52 +0000
committerDerick Rethans <github@derickrethans.nl>2013-03-31 10:45:01 +0100
commit58a8013e5ff8174aeac4cb38c50c435de9ea5622 (patch)
treedf419bbc623f2a7945d70d863d250e415afe20f4 /ext/date/lib/timelib.c
parenta4ca01cc2bc18204ad09ac4cc0f886539f8911e0 (diff)
downloadphp-git-58a8013e5ff8174aeac4cb38c50c435de9ea5622.tar.gz
Rebased to PHP-5.4
Implemented Dmitrys change from df97c3aa0d331be668bd5d8f27fff96d4e3ac1d7 Moved the timelib_parse_tz_cor function to ext/date/lib/timelib.c
Diffstat (limited to 'ext/date/lib/timelib.c')
-rw-r--r--ext/date/lib/timelib.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/ext/date/lib/timelib.c b/ext/date/lib/timelib.c
index 2f457a9882..84354e300f 100644
--- a/ext/date/lib/timelib.c
+++ b/ext/date/lib/timelib.c
@@ -30,6 +30,8 @@
#define TIMELIB_LLABS(y) (y < 0 ? (y * -1) : y)
+#define HOUR(a) (int)(a * 60)
+
timelib_time* timelib_time_ctor(void)
{
timelib_time *t;
@@ -284,3 +286,35 @@ void timelib_dump_rel_time(timelib_rel_time *d)
printf("\n");
}
+long timelib_parse_tz_cor(char **ptr)
+{
+ char *begin = *ptr, *end;
+ long tmp;
+
+ while (isdigit(**ptr) || **ptr == ':') {
+ ++*ptr;
+ }
+ end = *ptr;
+ switch (end - begin) {
+ case 1:
+ case 2:
+ return HOUR(strtol(begin, NULL, 10));
+ break;
+ case 3:
+ case 4:
+ 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:
+ tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);
+ return tmp;
+ }
+ return 0;
+}