Comments (4)
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.
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.
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.
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)
- Method duplication exception after running **v up** (pref.c.v and pref.v) HOT 3
- Library not found on compilation HOT 3
- cannot use modules that use mbedtls on macos arm with tcc HOT 2
- Long function signatures should break HOT 8
- Empty lines after function signature are removed HOT 1
- a V compiler bug
- I want to use this if
- The "Array Slices" section in the V documentation is incorrect HOT 5
- operator overloading not work: invalid operator `+` to `voidptr` and `voidptr` HOT 5
- v broken again on freebsd when using clang, the default compiler HOT 1
- Compiler bug when trying to return an interface-optional with a fallback default value
- Sorting an array of references HOT 9
- Building 0.4.6 release: `V panic: No such file or directory; code: 2` HOT 13
- V allows duplicated operator method
- x &&= y is not implemented HOT 4
- x.json2 fails to decode a map with number keys HOT 2
- eof ignored because of <> HOT 1
- when <circular> printing does not show the number of item in the array HOT 2
- builder error: cannot convert 'struct array' to 'struct array *'
- Including Homebrew's sshlib fails to compile HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from v.