janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.45k stars 223 forks source link

os/date problem ? #1214

Closed fnaj77 closed 1 year ago

fnaj77 commented 1 year ago

Hi to all, I'm having some issues using os/date, but maybe I'm misunderstanding its use so, please, correct me if I'm wrong.

I have this very simple janet script:

$cat os_date.janet

(defn get-time-stamp [] (let [{:month-day dd :month mm :year yy :hours hh :minutes min :seconds ss} (os/date)] (string dd "/" mm "/" yy ", " hh ":" min ":" ss)))

(print (get-time-stamp))

and, if I run it now, I get:

$ janet os_date.janet 6/6/2023, 16:13:16

but, I get a completely different result if I use linux date command:

$ date "+%D, %H:%M:%S" 07/07/23, 18:13:16

or even python:

$ python3 -c 'import datetime; print(datetime.datetime.now().strftime("%m/%d/%Y, %H:%M:%S")) 07/07/23, 18:13:18

I'm running the latest janet version (1.29.1-026c64fa) compiled from source on a ubuntu 22.10 machine.

I can imagine that there could be a time zone problem and therefore the hour does not coincide, but the day and month ?

Thank you guys for your incredible work on janet!

zevv commented 1 year ago

Yeah, os/date is a bit funny like that, but what you see matches with the documentation, look at https://janet-lang.org/api/index.html#os/date for more details.

fnaj77 commented 1 year ago

Thank you very much for your quick reply @zevv ! It was my fault, I totally miss that bit of info in the doc.

Maybe introducing an optional flag for a one based day and month could be a thing. I'm curious why day and month are zero based and year is not.

Anyway, I'm closing this issue, thanks again for the incredible work!

zevv commented 1 year ago

I'm curious why day and month are zero based and year is not.

Well, year is also zero based. There is such a thing as "the year zero", but there is no such thing as "day of the month zero"

CosmicToast commented 1 year ago

If you're looking to produce standard-ish timestamps, you should look into janet-date. I'll (eventually) finalize the move (fingers crossed for september-october, due to recent developments there's yet another obstacle now), at which point I'll look into getting it merged into spork.

fnaj77 commented 1 year ago

If you're looking to produce standard-ish timestamps, you should look into janet-date. I'll (eventually) finalize the move (fingers crossed for september-october, due to recent developments there's yet another obstacle now), at which point I'll look into getting it merged into spork.

Thank you @CosmicToast, I'll definitely take a look at your lib as soon as it will be released!

CosmicToast commented 1 year ago

Oh the library is released and ready as far as I'm concerned. Spork is the "contrib" standard library, that I may try to add the same functionality into later. As it is, everything is fine to go as of around a month ago.

pepe commented 1 year ago

I would love to see janet-date in the spork. When I consolidate GP a little more, I will change my own date time with it. If it were in the spork, it would be even better 😍.