Giter VIP home page Giter VIP logo

Comments (3)

nothingTVatYT avatar nothingTVatYT commented on May 30, 2024

Further testing brings up another problem:

    // check with C functions
    tm tm;
    tm.tm_year = year - 1900;
    tm.tm_mon = month - 1;
    tm.tm_mday = day;
    tm.tm_hour = hour;
    tm.tm_min = minute;
    tm.tm_sec = second;
    tm.tm_isdst = 0;
    const time_t t = mktime(&tm);
    LOG(Info, "Time structure constructed with C function: {0}, time_t={1}", String(ctime(&t)), t);
    const auto dt2 = DateTime::FromUnixTimestamp(t);
    LOG(Info, "results in {0} (ticks={1})", dt2, dt2.Ticks);
    // this should be the same as dt1 - milliseconds
    LOG(Info, "Expected difference is {0}ms, actually is {1} ticks", millisecond, (dt1-dt2).Ticks);
    const auto t2 = dt1.ToUnixTimestamp();
    if (t != t2)
        LOG(Warning, "timestamps differ: DateTime example: {0}, should be: {1}", t2, t);

writes:

[ 00:57:19.968 ]: [Info] Time structure constructed with C function: Sat Dec 16 23:50:13 2023
, time_t=1702767013
[ 00:57:19.968 ]: [Info] results in 2023-12-17 22:50:13 (ticks=638383638130000000)
[ 00:57:19.968 ]: [Info] Expected difference is 5ms, actually is 36000050000 ticks
[ 01:04:33.652 ]: [Warning] timestamps differ: DateTime example: 1702770613, should be: 1702767013

from flaxengine.

nothingTVatYT avatar nothingTVatYT commented on May 30, 2024

This leads to weird results as in:

    // check TZ
    DateTime local = DateTime::Now();
    DateTime nowInUTC = DateTime::NowUTC();
    LOG(Info, "difference between local ({1}) and UTC ({2}) is {0}", local - nowInUTC, local, nowInUTC);
    LOG(Info, "hours local - hours in UTC is {0}", local.GetHour() - nowInUTC.GetHour());
    LOG(Info, "day*24+hours local - UTC is {0}", (local.GetDay() * 24 + local.GetHour()) - (nowInUTC.GetDay() * 24 + nowInUTC.GetHour()));
[ 01:23:33.440 ]: [Info] difference between local (2023-12-29 00:38:06) and UTC (2023-12-29 23:38:06) is 01:00:00.0000000
[ 01:23:33.440 ]: [Info] hours local - hours in UTC is -23
[ 01:23:33.440 ]: [Info] day*24+hours local - UTC is -23

The difference of one hour is correct for my timezone but the difference days*24 + hours should be one hour as well (as long as it's the same month of course).

from flaxengine.

mafiesto4 avatar mafiesto4 commented on May 30, 2024

Fixed in 976d099. Also, added unit test with your sample code to ensure it's always working.

from flaxengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.