55import re
66
77import arrow
8- from workflow import ICON_CLOCK , ICON_NOTE , ICON_ERROR
8+ from ualfred import ICON_CLOCK , ICON_ERROR , ICON_NOTE
99
1010DEFAULT_FEEDBACK = [
1111 {
12- ' title' : 'Please enter timestamp, datetime string, "now", or space' ,
13- ' subtitle' : ' Examples: 1607609661, 2020-12-10 22:14:33, now' ,
14- ' valid' : False ,
15- ' icon' : ICON_ERROR ,
12+ " title" : 'Please enter timestamp, datetime string, "now", or space' ,
13+ " subtitle" : " Examples: 1607609661, 2020-12-10 22:14:33, now" ,
14+ " valid" : False ,
15+ " icon" : ICON_ERROR ,
1616 },
1717 {
18- ' title' : ' Change time zone or time shift' ,
19- ' subtitle' : ' Examples: now +08, now +1d' ,
20- ' valid' : False ,
21- ' icon' : ICON_ERROR ,
18+ " title" : " Change time zone or time shift" ,
19+ " subtitle" : " Examples: now +08, now +1d" ,
20+ " valid" : False ,
21+ " icon" : ICON_ERROR ,
2222 },
2323]
2424
2525SHIFT_UNIT_MAP = {
26- 'ms' : ' microseconds' ,
27- 's' : ' seconds' ,
28- 'm' : ' minutes' ,
29- 'h' : ' hours' ,
30- 'd' : ' days' ,
31- 'w' : ' weeks' ,
32- 'M' : ' months' ,
33- 'q' : ' quarters' ,
34- 'y' : ' years' ,
26+ "ms" : " microseconds" ,
27+ "s" : " seconds" ,
28+ "m" : " minutes" ,
29+ "h" : " hours" ,
30+ "d" : " days" ,
31+ "w" : " weeks" ,
32+ "M" : " months" ,
33+ "q" : " quarters" ,
34+ "y" : " years" ,
3535}
3636
3737FORMAT_LIST = (
38- (ICON_NOTE , True , 'X' , 'Timestamp(s)' ),
39- (ICON_NOTE , True , 'x' , 'Timestamp(us)' ),
40- (
41- ICON_CLOCK , False , 'W, DDDD[th day]' ,
42- 'ISO Week date and Day for year'
43- ),
44- (ICON_CLOCK , False , 'YYYY-MM-DD HH:mm:ss' , 'Date and Time' ),
45- (ICON_CLOCK , False , 'YYYY-MM-DD HH:mm:ss.SSSSSS' , 'Date and Time' ),
46- (ICON_CLOCK , False , arrow .FORMAT_RFC3339 , 'RFC3339 Format' ),
38+ (ICON_NOTE , True , "X" , "Timestamp(s)" ),
39+ (ICON_NOTE , True , "x" , "Timestamp(us)" ),
40+ (ICON_CLOCK , False , "W, DDDD[th day]" , "ISO Week date and Day for year" ),
41+ (ICON_CLOCK , False , "YYYY-MM-DD HH:mm:ss" , "Date and Time" ),
42+ (ICON_CLOCK , False , "YYYY-MM-DD HH:mm:ss.SSSSSS" , "Date and Time" ),
43+ (ICON_CLOCK , False , arrow .FORMAT_RFC3339 , "RFC3339 Format" ),
4744 ( # https://www.w3.org/TR/NOTE-datetime
48- ICON_CLOCK , False , 'YYYY-MM-DDTHH:mm:ssZZ' ,
49- 'ISO 8601/W3C Format'
45+ ICON_CLOCK ,
46+ False ,
47+ "YYYY-MM-DDTHH:mm:ssZZ" ,
48+ "ISO 8601/W3C Format" ,
5049 ),
51- (ICON_CLOCK , False , arrow .FORMAT_RFC850 , ' RFC850 Format' ),
50+ (ICON_CLOCK , False , arrow .FORMAT_RFC850 , " RFC850 Format" ),
5251)
5352
54- RE_TIMEZONE = ' ^[+-][0-9]{2}$'
55- RE_SHIFT = ' ^[+-][0-9]+[smhdwMy]$'
53+ RE_TIMEZONE = " ^[+-][0-9]{2}$"
54+ RE_SHIFT = " ^[+-][0-9]+[smhdwMy]$"
5655
5756
5857class Time (object ):
@@ -74,17 +73,17 @@ def query(self):
7473
7574 @query .setter
7675 def query (self , value ):
77- self ._query = value .strip (' ' )
76+ self ._query = value .strip (" " )
7877
7978 def do_parser (self ):
80- self .wf .logger .debug ('query string:{} {}' . format (
81- type (self .wf .args [0 ]), self .wf .args [0 ])
79+ self .wf .logger .debug (
80+ "query string:{} {}" . format ( type (self .wf .args [0 ]), self .wf .args [0 ])
8281 )
8382
8483 try :
85- self .query = self .wf .args [0 ].encode (' utf8' )
84+ self .query = self .wf .args [0 ].encode (" utf8" )
8685 except IndexError :
87- self .wf .logger .debug (' parser workflow args failed.' )
86+ self .wf .logger .debug (" parser workflow args failed." )
8887 return False
8988
9089 while True :
@@ -96,34 +95,34 @@ def do_parser(self):
9695
9796 def _parser_extend_info (self ):
9897 """parser timezone, shift"""
99- index = self .query .rfind (' ' )
98+ index = self .query .rfind (" " )
10099 if index == - 1 :
101- query = ''
100+ query = ""
102101 info = self .query
103102 else :
104103 query = self .query [:index ]
105- info = self .query [index + 1 :].strip (' ' )
104+ info = self .query [index + 1 :].strip (" " )
106105
107106 # time zone
108- if info .upper () == ' UTC' or info == ' +00' or info == ' -00' :
107+ if info .upper () == " UTC" or info == " +00" or info == " -00" :
109108 self .query = query
110- self .zone = ' UTC'
111- self .wf .logger .debug (' found zone info:{}' .format (self .zone ))
109+ self .zone = " UTC"
110+ self .wf .logger .debug (" found zone info:{}" .format (self .zone ))
112111 return True
113112
114113 r = re .match (RE_TIMEZONE , info )
115114 if r :
116115 self .query = query
117116 self .zone = info
118- self .wf .logger .debug (' found zone info:{}' .format (self .zone ))
117+ self .wf .logger .debug (" found zone info:{}" .format (self .zone ))
119118 return True
120119
121120 # time shift TODO
122121 r = re .match (RE_SHIFT , info )
123122 if r :
124123 self .query = query
125124 self .shift = info
126- self .wf .logger .debug (' found shift info:{}' .format (self .shift ))
125+ self .wf .logger .debug (" found shift info:{}" .format (self .shift ))
127126 return True
128127
129128 return False
@@ -141,14 +140,12 @@ def _parser_datetime(self):
141140 except arrow .ParserError :
142141 pass
143142
144- if self .query == ' now' or self .query == '' :
143+ if self .query == " now" or self .query == "" :
145144 self .now = True
146145 self .time = arrow .now ()
147146 return True
148147
149- self .wf .logger .debug (
150- 'parser datetime error,query string:{}' .format (self .query )
151- )
148+ self .wf .logger .debug ("parser datetime error,query string:{}" .format (self .query ))
152149 return False
153150
154151 def _apply_shift (self ):
@@ -168,40 +165,42 @@ def get_feedback(self):
168165 return DEFAULT_FEEDBACK
169166
170167 if self .now :
171- desc_now = ' Now, '
168+ desc_now = " Now, "
172169 else :
173- desc_now = ''
170+ desc_now = ""
174171
175172 f = list ()
176173 for icon , force_utc , fmt , desc_format in FORMAT_LIST :
177174 # time shift
178175 if self .shift :
179- desc_shift = ' {}, ' .format (self .shift )
176+ desc_shift = " {}, " .format (self .shift )
180177 else :
181- desc_shift = ''
178+ desc_shift = ""
182179
183180 # time znone
184181 if force_utc :
185- self .time = self .time .to (' UTC' )
186- desc_zone = ' UTC'
182+ self .time = self .time .to (" UTC" )
183+ desc_zone = " UTC"
187184 elif self .zone and not force_utc :
188185 self .time = self .time .to (self .zone )
189186 desc_zone = self .zone
190187 else :
191- self .time = self .time .to (' local' )
192- desc_zone = ' Local'
188+ self .time = self .time .to (" local" )
189+ desc_zone = " Local"
193190
194191 value = self .time .format (fmt )
195- subtitle = ' {}{}[{}] {}' .format (
192+ subtitle = " {}{}[{}] {}" .format (
196193 desc_now , desc_shift , desc_zone , desc_format
197194 )
198- f .append ({
199- 'title' : value ,
200- 'subtitle' : subtitle ,
201- 'valid' : True ,
202- 'arg' : value ,
203- 'icon' : icon ,
204- })
195+ f .append (
196+ {
197+ "title" : value ,
198+ "subtitle" : subtitle ,
199+ "valid" : True ,
200+ "arg" : value ,
201+ "icon" : icon ,
202+ }
203+ )
205204
206205 return f
207206
0 commit comments