Giter VIP home page Giter VIP logo

Comments (4)

felipensp avatar felipensp commented on July 20, 2024 1

Does not seems a bug to me. The time.now() has ns but the time.parse result does not. So obviously will be the delta there.

from v.

JalonSolov avatar JalonSolov commented on July 20, 2024 1

Subtracting one time value from another returns a Duration, which is just an i64 number of nanoseconds.

You're converting that to an int, which is what gives you the crazy number of seconds.

Now... that said, it doesn't appear that the - function is working correctly, as it should be a whole lot more nanoseconds than what's being shown.

Here it is without the cast (or shelling out to cowsay...):

import time

now := time.now()
then := time.parse("2024-03-06 17:28:00")!
delta := then - now
println('ETA: ${delta} or ${delta.seconds()} seconds')

With that change I get

ETA: -924ns or -1.399575694117924e+06 seconds

(of course, different numbers every time)

Those numbers hardly look correct.

from v.

hholst80 avatar hholst80 commented on July 20, 2024

I think you are correct. I am probably looking for a Unix now timestamp with a second resolution.

However, there seems still to be an issue with the display (to string) method for negative durations. I am confused at least.

    now := time.now()
    then := time.parse("2024-03-06 17:28:00")!
    delta := then - now
    seconds := int(delta.seconds()) // this will be plenty, but ${delta} will only give negative ns fraction
    os.system("echo ETA: ${delta} or ${seconds} seconds | cowsay")

 ________________________________
ETA: -796ns or -693579 seconds >
 --------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

( I wrote this on the train so my son would not have to ask me when we arrive at our destination... ) ;-)

from v.

hholst80 avatar hholst80 commented on July 20, 2024

The somewhat spurious output fromthe string representation made me think that Durations were limited to non-negatives. I think this was just an error in how they are represented as strings.

from v.

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.