@@ -6,7 +6,7 @@ use chrono::Local;
6
6
7
7
use chrono:: { Datelike , Duration , NaiveDate } ;
8
8
9
- use lazy_static :: lazy_static ;
9
+ use once_cell :: sync :: Lazy ;
10
10
11
11
/// The date value
12
12
#[ derive( Clone , Copy , Debug , Default ) ]
@@ -222,59 +222,58 @@ pub fn month_as_string(date: NaiveDate) -> String {
222
222
date. format ( "%B" ) . to_string ( )
223
223
}
224
224
225
- lazy_static ! {
226
- /// Gets the length of the longest month name.
227
- pub static ref MAX_MONTH_STR_LEN : usize = {
228
- let months = [
229
- NaiveDate :: from_ymd_opt( 0 , 1 , 1 ) . expect( "Year, Month or Day doesnt Exist" ) ,
230
- NaiveDate :: from_ymd_opt( 0 , 2 , 1 ) . expect( "Year, Month or Day doesnt Exist" ) ,
231
- NaiveDate :: from_ymd_opt( 0 , 3 , 1 ) . expect( "Year, Month or Day doesnt Exist" ) ,
232
- NaiveDate :: from_ymd_opt( 0 , 4 , 1 ) . expect( "Year, Month or Day doesnt Exist" ) ,
233
- NaiveDate :: from_ymd_opt( 0 , 5 , 1 ) . expect( "Year, Month or Day doesnt Exist" ) ,
234
- NaiveDate :: from_ymd_opt( 0 , 6 , 1 ) . expect( "Year, Month or Day doesnt Exist" ) ,
235
- NaiveDate :: from_ymd_opt( 0 , 7 , 1 ) . expect( "Year, Month or Day doesnt Exist" ) ,
236
- NaiveDate :: from_ymd_opt( 0 , 8 , 1 ) . expect( "Year, Month or Day doesnt Exist" ) ,
237
- NaiveDate :: from_ymd_opt( 0 , 9 , 1 ) . expect( "Year, Month or Day doesnt Exist" ) ,
238
- NaiveDate :: from_ymd_opt( 0 , 10 , 1 ) . expect( "Year, Month or Day doesnt Exist" ) ,
239
- NaiveDate :: from_ymd_opt( 0 , 11 , 1 ) . expect( "Year, Month or Day doesnt Exist" ) ,
240
- NaiveDate :: from_ymd_opt( 0 , 12 , 1 ) . expect( "Year, Month or Day doesnt Exist" ) ,
241
- ] ;
242
-
243
- let max = months. iter( )
244
- . map( |m| month_as_string( * m) )
245
- . map( |s| s. len( ) )
246
- . max( ) . expect( "There should be a maximum element" ) ;
247
-
248
- max
249
- } ;
250
-
251
- /// Gets the labels of the weekdays containing the first two characters of
252
- /// the weekdays.
253
- pub static ref WEEKDAY_LABELS : Vec <String > = {
254
- let days = [
255
- // Monday
256
- NaiveDate :: from_ymd_opt( 2020 , 6 , 1 ) . expect( "Year, Month or Day doesnt Exist" ) ,
257
- // Tuesday
258
- NaiveDate :: from_ymd_opt( 2020 , 6 , 2 ) . expect( "Year, Month or Day doesnt Exist" ) ,
259
- // Wednesday
260
- NaiveDate :: from_ymd_opt( 2020 , 6 , 3 ) . expect( "Year, Month or Day doesnt Exist" ) ,
261
- // Thursday
262
- NaiveDate :: from_ymd_opt( 2020 , 6 , 4 ) . expect( "Year, Month or Day doesnt Exist" ) ,
263
- // Friday
264
- NaiveDate :: from_ymd_opt( 2020 , 6 , 5 ) . expect( "Year, Month or Day doesnt Exist" ) ,
265
- // Saturday
266
- NaiveDate :: from_ymd_opt( 2020 , 6 , 6 ) . expect( "Year, Month or Day doesnt Exist" ) ,
267
- // Sunday
268
- NaiveDate :: from_ymd_opt( 2020 , 6 , 7 ) . expect( "Year, Month or Day doesnt Exist" ) ,
269
-
270
- ] ;
271
-
272
- days. iter( )
273
- . map( |d| d. format( "%a" ) . to_string( ) )
274
- . map( |s| s[ 0 ..2 ] . to_owned( ) )
275
- . collect( )
276
- } ;
277
- }
225
+ /// Gets the length of the longest month name.
226
+ pub static MAX_MONTH_STR_LEN : Lazy < usize > = Lazy :: new ( || {
227
+ let months = [
228
+ NaiveDate :: from_ymd_opt ( 0 , 1 , 1 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
229
+ NaiveDate :: from_ymd_opt ( 0 , 2 , 1 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
230
+ NaiveDate :: from_ymd_opt ( 0 , 3 , 1 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
231
+ NaiveDate :: from_ymd_opt ( 0 , 4 , 1 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
232
+ NaiveDate :: from_ymd_opt ( 0 , 5 , 1 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
233
+ NaiveDate :: from_ymd_opt ( 0 , 6 , 1 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
234
+ NaiveDate :: from_ymd_opt ( 0 , 7 , 1 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
235
+ NaiveDate :: from_ymd_opt ( 0 , 8 , 1 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
236
+ NaiveDate :: from_ymd_opt ( 0 , 9 , 1 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
237
+ NaiveDate :: from_ymd_opt ( 0 , 10 , 1 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
238
+ NaiveDate :: from_ymd_opt ( 0 , 11 , 1 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
239
+ NaiveDate :: from_ymd_opt ( 0 , 12 , 1 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
240
+ ] ;
241
+
242
+ let max = months
243
+ . iter ( )
244
+ . map ( |m| month_as_string ( * m) )
245
+ . map ( |s| s. len ( ) )
246
+ . max ( )
247
+ . expect ( "There should be a maximum element" ) ;
248
+
249
+ max
250
+ } ) ;
251
+
252
+ /// Gets the labels of the weekdays containing the first two characters of
253
+ /// the weekdays.
254
+ pub static WEEKDAY_LABELS : Lazy < Vec < String > > = Lazy :: new ( || {
255
+ let days = [
256
+ // Monday
257
+ NaiveDate :: from_ymd_opt ( 2020 , 6 , 1 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
258
+ // Tuesday
259
+ NaiveDate :: from_ymd_opt ( 2020 , 6 , 2 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
260
+ // Wednesday
261
+ NaiveDate :: from_ymd_opt ( 2020 , 6 , 3 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
262
+ // Thursday
263
+ NaiveDate :: from_ymd_opt ( 2020 , 6 , 4 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
264
+ // Friday
265
+ NaiveDate :: from_ymd_opt ( 2020 , 6 , 5 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
266
+ // Saturday
267
+ NaiveDate :: from_ymd_opt ( 2020 , 6 , 6 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
268
+ // Sunday
269
+ NaiveDate :: from_ymd_opt ( 2020 , 6 , 7 ) . expect ( "Year, Month or Day doesnt Exist" ) ,
270
+ ] ;
271
+
272
+ days. iter ( )
273
+ . map ( |d| d. format ( "%a" ) . to_string ( ) )
274
+ . map ( |s| s[ 0 ..2 ] . to_owned ( ) )
275
+ . collect ( )
276
+ } ) ;
278
277
279
278
#[ cfg( test) ]
280
279
0 commit comments