Update timelib and datetime functons to match

Esse commit está contido em:
Paul Tarjan
2013-06-21 18:24:39 -07:00
commit de Sara Golemon
commit 5d695acedb
123 arquivos alterados com 20013 adições e 34627 exclusões
+2 -1
Ver Arquivo
@@ -55,7 +55,8 @@ bool DateInterval::setDateString(CStrRef date_string) {
timelib_error_container *errors = nullptr;
time = timelib_strtotime((char*)date_string.data(), date_string.size(),
&errors, TimeZone::GetDatabase());
&errors, TimeZone::GetDatabase(),
TimeZone::GetTimeZoneInfoRaw);
int error_count = errors->error_count;
DateTime::setLastErrors(errors);
+8 -5
Ver Arquivo
@@ -153,7 +153,7 @@ Array DateTime::Parse(CStrRef datetime) {
struct timelib_error_container *error;
timelib_time *parsed_time =
timelib_strtotime((char*)datetime.data(), datetime.size(), &error,
TimeZone::GetDatabase());
TimeZone::GetDatabase(), TimeZone::GetTimeZoneInfoRaw);
Array ret;
PHP_DATE_PARSE_DATE_SET_TIME_ELEMENT(s_year, y);
@@ -422,7 +422,8 @@ void DateTime::setTimezone(SmartObject<TimeZone> timezone) {
void DateTime::modify(CStrRef diff) {
timelib_time *tmp_time = timelib_strtotime((char*)diff.data(), diff.size(),
nullptr, TimeZone::GetDatabase());
nullptr, TimeZone::GetDatabase(),
TimeZone::GetTimeZoneInfoRaw);
internalModify(&(tmp_time->relative), tmp_time->have_relative, 1);
timelib_time_dtor(tmp_time);
}
@@ -739,13 +740,15 @@ bool DateTime::fromString(CStrRef input, SmartObject<TimeZone> tz,
if (format) {
#ifdef TIMELIB_HAVE_INTERVAL
t = timelib_parse_from_format((char*)format, (char*)input.data(),
input.size(), &error, TimeZone::GetDatabase());
input.size(), &error, TimeZone::GetDatabase(),
TimeZone::GetTimeZoneInfoRaw);
#else
throw NotImplementedException("timelib version too old");
#endif
} else {
t = timelib_strtotime((char*)input.data(), input.size(),
&error, TimeZone::GetDatabase());
&error, TimeZone::GetDatabase(),
TimeZone::GetTimeZoneInfoRaw);
}
int error1 = error->error_count;
setLastErrors(error);
@@ -772,7 +775,7 @@ bool DateTime::fromString(CStrRef input, SmartObject<TimeZone> tz,
}
m_time = TimePtr(t, time_deleter());
m_tz = NEWOBJ(TimeZone)(t->tz_info);
m_tz = NEWOBJ(TimeZone)(timelib_tzinfo_clone(t->tz_info));
return true;
}
+10 -6
Ver Arquivo
@@ -87,22 +87,26 @@ const timelib_tzdb *TimeZone::GetDatabase() {
return Database;
}
TimeZoneInfo TimeZone::GetTimeZoneInfo(CStrRef name) {
TimeZoneInfo TimeZone::GetTimeZoneInfo(char* name, const timelib_tzdb* db) {
MapStringToTimeZoneInfo &Cache = s_timezone_data->Cache;
MapStringToTimeZoneInfo::const_iterator iter = Cache.find(name.data());
MapStringToTimeZoneInfo::const_iterator iter = Cache.find(name);
if (iter != Cache.end()) {
return iter->second;
}
TimeZoneInfo tzi(timelib_parse_tzfile((char *)name.data(), GetDatabase()),
tzinfo_deleter());
TimeZoneInfo tzi(timelib_parse_tzfile(name, db), tzinfo_deleter());
if (tzi) {
Cache[name.data()] = tzi;
Cache[name] = tzi;
}
return tzi;
}
timelib_tzinfo* TimeZone::GetTimeZoneInfoRaw(char* name,
const timelib_tzdb* db) {
return GetTimeZoneInfo(name, db).get();
}
bool TimeZone::IsValid(CStrRef name) {
return timelib_timezone_id_is_valid((char*)name.data(), GetDatabase());
}
@@ -201,7 +205,7 @@ TimeZone::TimeZone() {
}
TimeZone::TimeZone(CStrRef name) {
m_tzi = GetTimeZoneInfo(name);
m_tzi = GetTimeZoneInfo((char*)name.data(), GetDatabase());
}
TimeZone::TimeZone(timelib_tzinfo *tzi) {
+7 -3
Ver Arquivo
@@ -60,8 +60,8 @@ public:
* Constructing a timezone object by name or a raw pointer (internal).
*/
TimeZone();
TimeZone(CStrRef name);
TimeZone(timelib_tzinfo *tzi);
explicit TimeZone(CStrRef name);
explicit TimeZone(timelib_tzinfo *tzi);
static StaticString s_class_name;
// overriding ResourceData
@@ -135,7 +135,11 @@ private:
/**
* Look up cache and if found return it, otherwise, read it from database.
*/
static TimeZoneInfo GetTimeZoneInfo(CStrRef name);
static TimeZoneInfo GetTimeZoneInfo(char* name, const timelib_tzdb* db);
/**
* only for timelib, don't use it unless you are passing to a timelib func
*/
static timelib_tzinfo* GetTimeZoneInfoRaw(char* name, const timelib_tzdb* db);
TimeZoneInfo m_tzi; // raw pointer
};
+10 -28
Ver Arquivo
@@ -1,49 +1,31 @@
<?php
/*
* These tests only "work" depending on the version of timelib we're
* linked with.
*
* We've set them up to pass anyway, using the error handler. This is
* a little inconvenient (as the output is entirely one bool ...), but
* better than no way to test.
*/
function handler() {
var_dump(true);
}
set_error_handler('handler');
function do_date_diff() {
function test_date_diff() {
$dt1 = date_create("2010-08-02");
$dt2 = date_create("2010-08-30");
$interval = date_diff($dt1, $dt2, true);
return date_interval_format($interval, "%d") === "28";
return date_interval_format($interval, "%d");
}
function test_date_interval_create_from_date_string() {
$interval = date_interval_create_from_date_string("2 weeks");
return date_interval_format($interval, "%d") === "14";
return date_interval_format($interval, "%d");
}
function test_date_sub() {
$datetime = date_create("2010-08-16");
$interval = date_interval_create_from_date_string("2 weeks");
$dt2 = date_sub($datetime, $interval);
return date_format($dt2, "Y-m-d") === "2010-08-02";
return date_format($dt2, "Y-m-d");
}
function test_timezone_location_get() {
$tz = timezone_open("Europe/Prague");
$loc = timezone_location_get(tz);
return count($loc) === 4 &&
(string)$loc['country_code'] === "CZ" &&
(int)((double)$loc['latitude'] * 100) === 5008 &&
(int)((double)$loc['longitude'] * 100) === 1443 &&
(string)$loc['comments'] === ""
;
$loc = timezone_location_get($tz);
return $loc;
}
var_dump(test_date_diff() &&
test_date_interval_create_from_date_string() &&
test_date_sub() &&
test_timezone_location_get());
var_dump(test_date_diff());
var_dump(test_date_interval_create_from_date_string());
var_dump(test_date_sub());
var_dump(test_timezone_location_get());
@@ -1 +1,13 @@
bool(true)
string(2) "28"
string(2) "14"
string(10) "2010-08-02"
array(4) {
["country_code"]=>
string(2) "CZ"
["latitude"]=>
float(50.08333)
["longitude"]=>
float(14.43333)
["comments"]=>
string(0) ""
}

Alguns arquivos não foram exibidos porque demasiados arquivos foram alterados neste diff Mostrar Mais