-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
date.go
46 lines (39 loc) · 783 Bytes
/
date.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"log"
"time"
)
type Date struct {
val string
}
func (k *Date) value() string {
return k.val
}
func date() element {
e := &Date{}
go func() {
for {
if val, err := e.read(); err == nil {
e.val = val
} else {
log.Printf("could not read date: %v", err)
}
time.Sleep(time.Second)
}
}()
return e
}
func (k *Date) read() (string, error) {
localTZ, err := time.LoadLocation("Europe/Vilnius")
if err != nil {
return "", err
}
extraTZ, err := time.LoadLocation("Europe/London")
if err != nil {
return "", err
}
local := time.Now().In(localTZ).Format("Mon _2 Jan 15:04")
extra := "UK " + time.Now().In(extraTZ).Format("15:04")
return fmt.Sprintf("^fg(white)%s ^i(%s) ^fg()%s", local, xbm("clock2"), extra), nil
}