-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (65 loc) · 1.25 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"context"
"fmt"
"log"
"strconv"
"time"
"github.com/piliming/convert_time/clip"
"github.com/araddon/dateparse"
"github.com/gen2brain/beeep"
)
var loc = time.Now().Location()
func main() {
watch(handle)
}
func watch(fn func(string)) {
ch := clip.AdaptWatchDoubleText(context.Background())
for s := range ch {
//fmt.Println(s)
fn(s)
}
}
func handle(s string) {
if len(s) > 40 {
return
}
n, _ := strconv.ParseInt(s, 10, 64)
if n > 0 {
handleNum(n)
} else {
handleText(s)
}
}
func handleNum(num int64) {
if num > 10000000 && num < 10013221020 {
handleS(num)
}
if num > 10013221020 && num < 2101322102000 {
handleS(num / 1000)
}
}
// 1701322102000
func handleS(num int64) {
tStr := time.Unix(num, 0).In(loc).Format("2006-01-02 15:04:05")
//fmt.Println(tStr)
notify(tStr)
}
func handleText(s string) {
t, err := dateparse.ParseLocal(s)
if err != nil {
log.Println(err)
return
}
ts := t.Unix()
//fmt.Println(t.Location().String())
content := fmt.Sprintf("%d - 已复制到剪切板", ts)
clip.Write(clip.FmtText, []byte(strconv.FormatInt(ts, 10)))
notify(content)
}
func notify(s string) {
err := beeep.Notify("时间转换", s, "assets/information.png")
if err != nil {
log.Println(err)
}
}