Skip to content

Commit

Permalink
When using fromTimeStamp with utc=true, make sure to initialise the t…
Browse files Browse the repository at this point in the history
…imezone to UTC

Summary: 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  0x00007fffeeae64e
Closes facebook#5547

Reviewed By: @sgolemon

Differential Revision: D2197285
  • Loading branch information
derickr authored and hhvm-bot committed Jul 8, 2015
1 parent 2a01bf4 commit 45c66fe
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hphp/runtime/base/datetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ void DateTime::fromTimeStamp(int64_t timestamp, bool utc /* = false */) {

timelib_time *t = timelib_time_ctor();
if (utc) {
t->zone_type = TIMELIB_ZONETYPE_OFFSET;
t->z = 0;
timelib_unixtime2gmt(t, (timelib_sll)m_timestamp);
} else {
if (!m_tz.get()) {
Expand Down

0 comments on commit 45c66fe

Please sign in to comment.