9d00a004b21791557c7d5cd1070b21054125b149
- Author
- ymlair <w_w_wcom@163.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
feat(tt): add plugin tt (#8273)
Diff
1diff --git a/plugins/tt/README.MD b/plugins/tt/README.MD
2new file mode 100644
3index 0000000000000000000000000000000000000000..6246488be7272f09f13f6d3868092af8822b453c
4--- /dev/null
5+++ b/plugins/tt/README.MD
6@@ -0,0 +1,26 @@
7+# TT
8+
9+This plugin provides mutual conversion of timestamp and date.
10+
11+To use it add tt to the plugins array in your zshrc file.
12+
13+```bash
14+plugins=(... tt)
15+```
16+# Example
17+
18+print timestamp for "2019-10-16"
19+```bash
20+tt 2019-10-16
21+```
22+
23+print timestamp for "2019-10-16 18:41:00"
24+```bash
25+tt "2019-10-16 18:41:00"
26+```
27+
28+print date for "1571222561"
29+```bash
30+tt 1571222561
31+```
32+echo 2019-10-16 18:42:41
33diff --git a/plugins/tt/tt.plugin.zsh b/plugins/tt/tt.plugin.zsh
34new file mode 100644
35index 0000000000000000000000000000000000000000..cffb4b82348eed2ac2f93029acd696e0f69969fa
36--- /dev/null
37+++ b/plugins/tt/tt.plugin.zsh
38@@ -0,0 +1,21 @@
39+#
40+# Functions
41+#
42+# timestamp to date Or date to timestamp
43+#
44+tt () {
45+ if [[ $1 =~ "-" ]]
46+ then
47+ if [[ $1 =~ " " ]]
48+ then
49+ date -j -f "%Y-%m-%d %H:%M:%S" "$1" +%s 2> /dev/null
50+ else
51+ date -j -f "%Y-%m-%d %H:%M:%S" "$1 00:00:00" +%s 2> /dev/null
52+ fi
53+ elif [[ $1 = "" ]]
54+ then
55+ date +%s
56+ else
57+ date -r $1 "+%Y-%m-%d %H:%M:%S"
58+ fi
59+}