Skip to content

boost::datetime::ptime shows wrong time of day #44

@cohem

Description

@cohem

I'm using:

It calculates hours as a negative value. For example, this time

auto time = boost::posix_time::from_iso_string("20230613T130922");

is shown as:

2023-6-13 -6-8:01:44 0ms 0us

The hour variable gets -68. The source of miscalculation is this division:

<Intrinsic Name="hour"        Expression="_t_hours()/3600000000"/>

Debugger seems to be treating the literal as uint32 and extends it to int64 this way:

auto hour = t_hours/static_cast<int>(3600000000);

I.e. it first converts it to int32, making it negative, and then extends the negative value to 64 bits.
This change fixes this:

<Intrinsic Name="hour"        Expression="_t_hours()/3600000000LL"/>
<Intrinsic Name="_t_minutes"  Expression="_t_hours()-3600000000LL*hour()"/>

(Note, boost::local_time::posix_time_zone_base also uses the constant).

This is probably a debugger bug, because it must be following C++ expression rules, and this calculations written in C++ give the right value. But I'm not sure.

auto time = boost::posix_time::from_iso_string("20230613T130922");  // To check it in "Locals" window
__int64 value = 212553464962000000ll;
auto x = value/86400000000;
auto t_hours = value-86400000000*x;
auto hour = t_hours/3600000000;

hour is 13.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions