@@ -7,11 +7,11 @@ use crate::api::news::get_list::NewsEntry;
7
7
use crate :: api:: post:: get_comment_list:: PostCommentEntry ;
8
8
use crate :: api:: post:: get_one:: PostEntry ;
9
9
use crate :: api:: user:: info:: UserInfo ;
10
+ use crate :: args:: TimeStyle ;
10
11
use crate :: infra:: iter:: IteratorExt ;
11
12
use crate :: infra:: str:: StrExt ;
12
- use crate :: infra:: time:: { fmt_time_to_string_friendly , patch_rfc3339 } ;
13
+ use crate :: infra:: time:: display_cnb_time ;
13
14
use anyhow:: Result ;
14
- use chrono:: { DateTime , Local , Utc } ;
15
15
use colored:: Colorize ;
16
16
use std:: fmt:: Display ;
17
17
use std:: ops:: Not ;
@@ -54,6 +54,7 @@ pub fn user_info(info: &Result<UserInfo>) {
54
54
}
55
55
56
56
pub fn list_ing (
57
+ time_style : & TimeStyle ,
57
58
ing_with_comment_list : & Result < Vec < ( IngEntry , Vec < IngCommentEntry > ) > > ,
58
59
rev : bool ,
59
60
align : bool ,
@@ -67,15 +68,9 @@ pub fn list_ing(
67
68
. iter ( )
68
69
. dyn_rev ( rev)
69
70
. for_each ( |( ing, comment_list) | {
70
- let create_time = {
71
- let rfc3339 = patch_rfc3339 ( & ing. create_time ) ;
72
- let dt = DateTime :: parse_from_rfc3339 ( & rfc3339)
73
- . unwrap_or_else ( |_| panic ! ( "Invalid RFC3339: {}" , rfc3339) )
74
- . with_timezone ( & Utc ) ;
75
- fmt_time_to_string_friendly ( dt. into ( ) , Local :: now ( ) )
76
- } ;
77
-
71
+ let create_time = display_cnb_time ( & ing. create_time , time_style) ;
78
72
print ! ( "{}" , create_time. dimmed( ) ) ;
73
+
79
74
let send_from_mark = match ing. send_from {
80
75
IngSendFrom :: Cli => Some ( "CLI" ) ,
81
76
IngSendFrom :: CellPhone => Some ( "Mobile" ) ,
@@ -154,7 +149,7 @@ pub fn show_post(entry: &Result<PostEntry>) {
154
149
}
155
150
}
156
151
157
- pub fn show_post_meta ( entry : & Result < PostEntry > ) {
152
+ pub fn show_post_meta ( time_style : & TimeStyle , entry : & Result < PostEntry > ) {
158
153
let entry = match entry {
159
154
Ok ( entry) => entry,
160
155
Err ( e) => return println_err ( e) ,
@@ -186,39 +181,25 @@ pub fn show_post_meta(entry: &Result<PostEntry>) {
186
181
println ! ( "Tags {}" , tags_text) ;
187
182
}
188
183
}
189
- let create_time = {
190
- let rfc3339 = patch_rfc3339 ( & entry. create_time ) ;
191
- let dt = DateTime :: parse_from_rfc3339 ( & rfc3339)
192
- . unwrap_or_else ( |_| panic ! ( "Invalid RFC3339: {}" , rfc3339) )
193
- . with_timezone ( & Utc ) ;
194
- fmt_time_to_string_friendly ( dt. into ( ) , Local :: now ( ) )
195
- } ;
184
+ let create_time = display_cnb_time ( & entry. create_time , time_style) ;
196
185
println ! ( "Create {}" , create_time) ;
197
- let modify_time = {
198
- let rfc3339 = patch_rfc3339 ( & entry. modify_time ) ;
199
- let dt = DateTime :: parse_from_rfc3339 ( & rfc3339)
200
- . unwrap_or_else ( |_| panic ! ( "Invalid RFC3339: {}" , rfc3339) )
201
- . with_timezone ( & Utc ) ;
202
- fmt_time_to_string_friendly ( dt. into ( ) , Local :: now ( ) )
203
- } ;
186
+ let modify_time = display_cnb_time ( & entry. create_time , time_style) ;
204
187
println ! ( "Modify {}" , modify_time) ;
205
188
println ! ( "Link https:{}" , entry. url) ;
206
189
}
207
190
208
- pub fn show_post_comment ( comment_list : & Result < Vec < PostCommentEntry > > , rev : bool ) {
191
+ pub fn show_post_comment (
192
+ time_style : & TimeStyle ,
193
+ comment_list : & Result < Vec < PostCommentEntry > > ,
194
+ rev : bool ,
195
+ ) {
209
196
let comment_list = match comment_list {
210
197
Ok ( entry) => entry,
211
198
Err ( e) => return println_err ( e) ,
212
199
} ;
213
200
214
201
comment_list. iter ( ) . dyn_rev ( rev) . for_each ( |comment| {
215
- let create_time = {
216
- let rfc3339 = patch_rfc3339 ( & comment. create_time ) ;
217
- let dt = DateTime :: parse_from_rfc3339 ( & rfc3339)
218
- . unwrap_or_else ( |_| panic ! ( "Invalid RFC3339: {}" , rfc3339) )
219
- . with_timezone ( & Utc ) ;
220
- fmt_time_to_string_friendly ( dt. into ( ) , Local :: now ( ) )
221
- } ;
202
+ let create_time = display_cnb_time ( & comment. create_time , time_style) ;
222
203
let floor_text = format ! ( "{}F" , comment. floor) ;
223
204
println ! ( "{} {}" , create_time. dimmed( ) , floor_text. dimmed( ) ) ;
224
205
println ! ( " {} {}" , comment. user_name. cyan( ) , comment. content) ;
@@ -271,21 +252,14 @@ pub fn println_result<T: Display>(result: &Result<T>) {
271
252
}
272
253
}
273
254
274
- pub fn list_news ( news_list : & Result < Vec < NewsEntry > > , rev : bool ) {
255
+ pub fn list_news ( time_style : & TimeStyle , news_list : & Result < Vec < NewsEntry > > , rev : bool ) {
275
256
let news_list = match news_list {
276
257
Ok ( o) => o,
277
258
Err ( e) => return println_err ( e) ,
278
259
} ;
279
260
280
261
news_list. iter ( ) . dyn_rev ( rev) . for_each ( |news| {
281
- let create_time = {
282
- let rfc3339 = patch_rfc3339 ( & news. create_time ) ;
283
- let dt = DateTime :: parse_from_rfc3339 ( & rfc3339)
284
- . unwrap_or_else ( |_| panic ! ( "Invalid RFC3339: {}" , rfc3339) )
285
- . with_timezone ( & Utc ) ;
286
- fmt_time_to_string_friendly ( dt. into ( ) , Local :: now ( ) )
287
- } ;
288
-
262
+ let create_time = display_cnb_time ( & news. create_time , time_style) ;
289
263
let url = format ! ( "https://news.cnblogs.com/n/{}" , news. id) ;
290
264
println ! ( "{} {}" , create_time. dimmed( ) , url. dimmed( ) , ) ;
291
265
println ! ( " {}" , news. title) ;
0 commit comments