Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using fromTimeStamp with utc=true, make sure to initialise the timezone to UTC #5547

Closed
wants to merge 1 commit into from

Conversation

derickr
Copy link
Contributor

@derickr derickr commented Jun 26, 2015

Without this change, the following code:

c_dt = HPHP::Unit::lookupClass(HPHP::s_DateTime.get());
assert(c_dt);
HPHP::ObjectData* obj = HPHP::ObjectData::newInstance(c_dt);

DateTimeData* data = Native::data<DateTimeData>(obj);
data->m_dt = makeSmartPtr<DateTime>(0, false);
data->m_dt->fromTimeStamp(milliseconds / 1000, true);

Would cause issues when var_dumping the returned object. var_dump would call
debugInfo on the object, which in turns tries to use zone_type_to_string, which
has an assertion if it can't find the type. With the above example, the zone
type would be false, and we'd get this assertion:

Program received signal SIGABRT, Aborted.
0x00007fffeeae5107 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56  ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  0x00007fffeeae5107 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007fffeeae64e8 in __GI_abort () at abort.c:89
#2  0x00000000027ef459 in HPHP::assert_fail (e=e@entry=0x2eefd44 "!\"Bad zone type\"", 
    file=file@entry=0x2f7b278 "/home/derick/dev/facebook-hhvm/hphp/runtime/ext/datetime/ext_datetime.cpp", line=line@entry=59, 
    func=func@entry=0x4081380 <HPHP::zone_type_to_string(int, HPHP::SmartPtr<HPHP::DateTime>)::__PRETTY_FUNCTION__> "HPHP::String HPHP::zone_type_to_string(int, HPHP::SmartPtr<HPHP::DateTime>)", msg="") at /home/derick/dev/facebook-hhvm/hphp/util/assertions.cpp:80
#3  0x00000000023c18cb in HPHP::zone_type_to_string (zoneType=<optimized out>, dt=...) at /home/derick/dev/facebook-hhvm/hphp/runtime/ext/datetime/ext_datetime.cpp:59
#4  0x00000000023c6222 in HPHP::DateTimeData::getDebugInfo (this=0x7fffe5c1d438) at /home/derick/dev/facebook-hhvm/hphp/runtime/ext/datetime/ext_datetime.cpp:307
#5  0x00000000015250d7 in HPHP::ObjectData::toArray (this=0x7fffe5c1d440, pubOnly=pubOnly@entry=false) at /home/derick/dev/facebook-hhvm/hphp/runtime/base/object-data.cpp:442
#6  0x00000000014861e2 in HPHP::Object::toArray (this=this@entry=0x7fffffffca40) at /home/derick/dev/facebook-hhvm/hphp/runtime/base/type-object.cpp:49

…imezone to UTC.

Without this change, the following code:

    c_dt = HPHP::Unit::lookupClass(HPHP::s_DateTime.get());
    assert(c_dt);
    HPHP::ObjectData* obj = HPHP::ObjectData::newInstance(c_dt);

    DateTimeData* data = Native::data<DateTimeData>(obj);
    data->m_dt = makeSmartPtr<DateTime>(0, false);
    data->m_dt->fromTimeStamp(milliseconds / 1000, true);

Would cause issues when var_dumping the returned object. var_dump would call
debugInfo on the object, which in turns tries to use zone_type_to_string, which
has an assertion if it can't find the type. With the above example, the zone
type would be false, and we'd get this assertion:

Program received signal SIGABRT, Aborted.
0x00007fffeeae5107 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56	../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
    file=file@entry=0x2f7b278 "/home/derick/dev/facebook-hhvm/hphp/runtime/ext/datetime/ext_datetime.cpp", line=line@entry=59,
    func=func@entry=0x4081380 <HPHP::zone_type_to_string(int, HPHP::SmartPtr<HPHP::DateTime>)::__PRETTY_FUNCTION__> "HPHP::String HPHP::zone_type_to_string(int, HPHP::SmartPtr<HPHP::DateTime>)", msg="") at /home/derick/dev/facebook-hhvm/hphp/util/assertions.cpp:80
@facebook-github-bot
Copy link
Contributor

This pull request has been imported into Phabricator, and discussion and review of the diff will take place at https://reviews.facebook.net/D40803

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants