mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-04 17:41:21 +03:00
/timestamp: Switch TZINFO with UTC offset
This commit is contained in:
parent
078fbbe828
commit
a90574126e
@ -285,8 +285,8 @@ func InitCommands(c *Commands) {
|
|||||||
|
|
||||||
c.Add(Command{
|
c.Add(Command{
|
||||||
Prefix: "/timestamp",
|
Prefix: "/timestamp",
|
||||||
PrefixHelp: "[TZINFO]",
|
PrefixHelp: "[UTC_OFFSET [LABEL]]",
|
||||||
Help: "Prefix messages with a timestamp. (Example: America/Toronto)",
|
Help: "Prefix messages with a timestamp. (Offset example: +5h45m)",
|
||||||
Handler: func(room *Room, msg message.CommandMsg) error {
|
Handler: func(room *Room, msg message.CommandMsg) error {
|
||||||
u := msg.From()
|
u := msg.From()
|
||||||
cfg := u.Config()
|
cfg := u.Config()
|
||||||
@ -296,12 +296,15 @@ func InitCommands(c *Commands) {
|
|||||||
// FIXME: This is an annoying format to demand from users, but
|
// FIXME: This is an annoying format to demand from users, but
|
||||||
// hopefully we can make it a non-primary flow if we add GeoIP
|
// hopefully we can make it a non-primary flow if we add GeoIP
|
||||||
// someday.
|
// someday.
|
||||||
timeLoc, err := time.LoadLocation(args[0])
|
offset, err := time.ParseDuration(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("%s: Use a location name such as \"America/Toronto\" or refer to the IANA Time Zone database for the full list of names: https://wikipedia.org/wiki/List_of_tz_database_time_zones", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cfg.Timezone = timeLoc
|
label := ""
|
||||||
|
if len(args) >= 2 {
|
||||||
|
label = args[1]
|
||||||
|
}
|
||||||
|
cfg.Timezone = time.FixedZone(label, int(offset.Seconds()))
|
||||||
cfg.Timestamp = true
|
cfg.Timestamp = true
|
||||||
} else {
|
} else {
|
||||||
cfg.Timestamp = !cfg.Timestamp
|
cfg.Timestamp = !cfg.Timestamp
|
||||||
@ -310,9 +313,10 @@ func InitCommands(c *Commands) {
|
|||||||
|
|
||||||
var body string
|
var body string
|
||||||
if cfg.Timestamp && cfg.Timezone != nil {
|
if cfg.Timestamp && cfg.Timezone != nil {
|
||||||
body = fmt.Sprintf("Timestamp is toggled ON with timezone %q", cfg.Timezone)
|
tzname := time.Now().In(cfg.Timezone).Format("MST")
|
||||||
|
body = fmt.Sprintf("Timestamp is toggled ON, timezone is %q", tzname)
|
||||||
} else if cfg.Timestamp {
|
} else if cfg.Timestamp {
|
||||||
body = "Timestamp is toggled ON"
|
body = "Timestamp is toggled ON, timezone is UTC"
|
||||||
} else {
|
} else {
|
||||||
body = "Timestamp is toggled OFF"
|
body = "Timestamp is toggled OFF"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user