Skip to content

Commit 47d1857

Browse files
committed
Update some display format
1 parent a9600b3 commit 47d1857

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

core.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,28 @@
77
import arrow
88
from workflow import ICON_CLOCK, ICON_NOTE, ICON_ERROR
99

10+
DEFAULT_FEEDBACK = [{
11+
'title': 'Please enter timestamp, datetime string, "now", or space',
12+
'subtitle': 'Examples: 1607609661, 2020-12-10 22:14:33, now +08',
13+
'valid': False,
14+
'icon': ICON_ERROR,
15+
}]
16+
1017
FORMAT_LIST = (
11-
(ICON_NOTE, 'X', 'UTC Timestamp (s)'),
12-
(ICON_NOTE, 'x', 'UTC Timestamp (us)'),
18+
(ICON_NOTE, True, 'X', 'Timestamp(s)'),
19+
(ICON_NOTE, True, 'x', 'Timestamp(us)'),
1320
(
14-
ICON_CLOCK, 'YYYY-MM-DD HH:mm:ss', 'Date and Time'
21+
ICON_CLOCK, False, 'YYYY-MM-DD HH:mm:ss', 'Date and Time'
1522
),
1623
(
17-
ICON_CLOCK, 'W, DDDD[th day]',
24+
ICON_CLOCK, False, 'W, DDDD[th day]',
1825
'ISO Week date and Day for year'
1926
),
2027
( # https://www.w3.org/TR/NOTE-datetime
21-
ICON_CLOCK, 'YYYY-MM-DDTHH:mm:ssZZ',
28+
ICON_CLOCK, False, 'YYYY-MM-DDTHH:mm:ssZZ',
2229
'W3C Format'
2330
),
24-
(ICON_CLOCK, arrow.FORMAT_RFC850, 'RFC850 Format'),
31+
(ICON_CLOCK, False, arrow.FORMAT_RFC850, 'RFC850 Format'),
2532
# FORMAT_RFC3339
2633
)
2734

@@ -119,27 +126,30 @@ def _parser_datetime(self):
119126

120127
def get_feedback(self):
121128
if self.time is None:
122-
return [{
123-
'title': 'Please enter timestamp, datetime string, "now", or space',
124-
'subtitle': 'Examples: 1607609661, 2020-12-10 22:14:33, now +08',
125-
'valid': False,
126-
'icon': ICON_ERROR,
127-
}]
129+
return DEFAULT_FEEDBACK
128130

129-
f = list()
130-
for icon, fmt, desc in FORMAT_LIST:
131-
if self.now:
132-
subtitle = 'Now, {}'.format(desc)
133-
else:
134-
subtitle = desc
131+
if self.now:
132+
desc_now = 'Now, '
133+
else:
134+
desc_now = ''
135135

136-
if self.zone:
137-
self.time = self.time.to(self.zone[:3])
138-
subtitle = '[{}]{}'.format(self.zone, subtitle)
136+
f = list()
137+
for icon, force_utc, fmt, desc_format in FORMAT_LIST:
138+
139+
if force_utc:
140+
self.time = self.time.to('UTC')
141+
desc_zone = 'UTC, '
142+
elif self.zone and not force_utc:
143+
self.time = self.time.to(self.zone)
144+
desc_zone = '{}, '.format(self.zone)
139145
else:
140146
self.time = self.time.to('local')
147+
desc_zone = 'Local, '
141148

142149
value = self.time.format(fmt)
150+
subtitle = '{}{}{}'.format(
151+
desc_now, desc_zone, desc_format
152+
)
143153
f.append({
144154
'title': value,
145155
'subtitle': subtitle,

0 commit comments

Comments
 (0)