-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timezone for timestamps #12
Comments
You're welcome! We do try to get the local timezone, then fall back to UTC if we can't: https://github.com/samwho/spacer/blob/main/src/main.rs#L94. I can add the timezone to the date output and that'll tell us for sure what the timezone is. I'm not actually sure what situations would cause |
Thanks :) After posting the issue I took a look at the source code and then at the rust docs and realized it was falling back to UTC, but I couldn't work out why the local timezone wasn't available to rust on any of the systems I tested on. Then I started looking at other ways to get the local timezone (which might also support passing an arbitrary timezone as a command-line argument), but it looks like it'd have to be platform dependent. I reckon it would be possible to get something working straightforwardly enough on my Linux systems by parsing edit: I did find this for timezone conversion: https://docs.rs/crate/tzdata/0.4.1. Doesn't address getting the local timezone, though (and yeah, it's parsing |
I just pushed a commit to the |
Thanks so much for the speedy update.
It works, and it's an improvement I think, but it hasn't picked up the daylight savings on my Arch workstation or on my Debian and Centos servers. I'm not immediately sure what to make of that (apart from the observation that daylight savings time is an obstructive anachronism at this point -- but that's not really very helpful :)). |
Why is time so hard. So what I think was causing it to fall back to UTC all the time was this: https://github.com/time-rs/time/blob/18cabd12bd4258622028ffa2d9a7cb935f549b8e/time/src/sys/local_offset_at/unix.rs#L144. Seems if you have multiple threads running, it will always fall back to UTC. The comment about it being conservative wasn't lying. To get around it, I fetch the local timezone prior to spawning the background thread I have no good theories about DST, though. |
I've put out https://github.com/samwho/spacer/releases/tag/v0.2 so you don't have to run from head anymore. |
Thanks! Tbh I'm not sure if being an hour out is better or worse than just doing UTC regardless. It's confusing either way. I have limited experience with rust, but would something like this be suitable? https://docs.rs/chrono/latest/chrono/ What do you feel about the possibility of adding the ability to specify a timezone? Would be a killer feature (for me, at least). |
Just as a quick update to this -- what I really want for myself is something like this:
I have a branch that does this and works on {Arch,Debian,Centos} Linux and Mac. I've not tried it on Windows (it does build, though, so I presume it's good), and it doesn't have proper tests (the accuracy of timestamps isn't currently tested, but test could be added to do some snapshot-style testings, perhaps -- e.g. that passing I haven't PR'd it until I know how you feel about #13 -- if you'd rather not have anything to do with this that's cool (I'll use my own fork!) -- but if this is a feature you'd be interested in having and this approach looks reasonable to you, I'd be pleased to help with anything else that needs doing to make it mergeable (code could very likely be improved -- I'm not much of a rustacean!). |
@simonwiles #13 has been merged, happy to review a PR for the For testing, you could add an enum variant to |
@simonwiles is it everything you hoped for? 🙂 |
Yes! I am an even happier |
Thank you for this tool -- it's so useful!
Bug report/feature request:
Unless I've missed something, the timestamps produced by
spacer
are in UTC regardless of the timezone of the system (or, indeed, anything else)? It would be great to have them follow the system, or, even better have them be configurable (I regularly work on servers in other timezones -- the logs and output I might be interested in following all use timestamps that match the timezone of the server, as they should, but it would be awesome to be able to pipe output tospacer
and seespacer
's timestamps in my own local timezone).The text was updated successfully, but these errors were encountered: