starship / starship

☄🌌️ The minimal, blazing-fast, and infinitely customizable prompt for any shell!
https://starship.rs
ISC License
45.69k stars 1.98k forks source link

Specify time zone in time module #431

Closed dead10ck closed 5 years ago

dead10ck commented 5 years ago

Feature Request

The time module currently only shows the local system's time. It would be nice if you could choose a time zone, e.g. so you could always show the timestamp in UTC.

jletey commented 5 years ago

@dead10ck If you direct your attention to the chrono format string used to format the time, you will see:

Shot 2019-09-26 at 16 44 35

However, if I understand correctly, this isn't what I think you want, is it?

dead10ck commented 5 years ago

I believe those are just for printing the time zone of a timestamp, which incidentally is always in the local time zone. The feature I am requesting is to choose the time zone of the timestamp shown in the prompt, instead of always showing the local time.

dead10ck commented 5 years ago

So for example, if you are in the PST time zone, right now with just

[time]
disabled = false

you would see:

at 12:36:17 ❯

but you could have a timezone option, so that e.g. you might have a config like:

[time]
disabled = false
timezone = "UTC"

and see:

at 19:36:17 ❯
jletey commented 5 years ago

Thanks for clarifying @dead10ck! I will start work on this!

keawade commented 5 years ago

@dead10ck, I've got a proof-of-concept going on my machine and I just want to double check that what I've got matches what you're asking for.

In this screenshot, you can see the result of updating my config file and then echoing the value I just saved in the config to render a new prompt with the new config being respected (Screenshot taken at roughly 12:25 UTC): Screenshot from 2019-09-30 07-26-20

Currently I have a config variable, utc_time_offset, that defaults to "local" to skip all tz logic or instead takes a string like "+3", "-6", etc and uses that to display the current time in that offset instead of your local timezone.

If this seems right then I'll open a PR after adding some better config input validation.

After that, I'd like to try to get actual timezone mapping so you could say timezone = "America_NewYork" or some other UTC timezone name instead of using offset numbers but from what I've seen of the chrono-tz crate, that may be easier said than done.

matchai commented 5 years ago

@keawade This is how I envisioned it working. Looks great to me! 👍

dead10ck commented 5 years ago

Awesome! Specifying an offset definitely gets the job done.