Calendar Package Updates in 2019 - New Features in Maple 2019 - Maplesoft

What's New in Maple 2019

Calendar Package Updates in 2019



Description 

  • The Calendar package has new commands for parsing and formatting Date and Time objects.
 

Formatting Dates and Times 

  • Use the Calendar:-Format command or the Calendar:-VariantFormat command to format a Date or UTC Time object as a string. You can do this in a locale-sensitive way by using the locale option.
 

  • Codes codes for formatting and parsing are specified according to the Unicode Technical Standard #35, "Unicode Locale Data Markup Language (LDML)", Part 4 (Dates).
 

> with( Calendar ):
 

> Format( Today() );
 

2019-01-28T06:14:18 EST
 

> Format( Today(), 'locale' = "fr" );
 

2019-01-28T06:14:19 UTC−5
 

> Format( Today(), "yyyy.MM.dd G 'at' HH:mm:ss zzz" );
 

2019.01.28 AD at 06:14:19 EST
 

> Format( Today(), "yyyy.MM.dd G 'um' HH:mm:ss zzz", 'locale' = "de" );
 

2019.01.28 n. Chr. um 06:14:19 GMT-5
 

> Format( Now( SystemUTCClock ), "K:mm a, z", 'locale' = "ja" );
 

6:14 HM, GMT-5
 

> Format( Now( SystemUTCClock ), "hh 'o''clock' a, zzzz" );
 

06 o'clock AM, Eastern Standard Time
 

  • You can use a different (printf-like) formatting string by using the command VariantFormat.
 

  • Unlike the similar command FormatTime in the StringTools package, the Calendar:-VariantFormat command supports the locale option, allowing you to format dates and times in a locale-sensitive way. Moreover, the Calendar package commands work directly with Date and UTC Time objects.
 

> VariantFormat( Today(), "%c" );
 

Mon Jan 28 06:14:19 2019
 

> VariantFormat( Today(), "%c", 'locale' = "id" );
 

Sen Jan 28 06:14:19 2019
 

> fmt := "EEEE, MMMM dd, yyyy GG, hh:mm:ss a":
 

> DocumentTools:-Tabulate( map( loc -> Format( Today(), fmt, ':-locale' = loc ), << "en", "fr", "de" > | < "ks", "ja", "ko" >> ) ):
 

 

Parsing Dates and Times 

  • As for formatting, there are new commands to parse dates in strings. These are Parse and VariantParse, corresponding to Format and VariantFormat, respectively.
 

  • Both Parse and VariantParse support the locale option.
 

> s := Format( Today(), "EEEE, MMMM dd, yyyy GG, hh:mm:ss a", 'locale' = "id" );
 

Typesetting:-mprintslash([s :=
 

> Parse( s, "EEEE, MMMM dd, yyyy GG, hh:mm:ss a", 'locale' = "id" );
 

Typesetting:-mrow(Typesetting:-mi(
 

> s := VariantFormat( Today(), "%c", 'locale' = "de" );
 

Typesetting:-mprintslash([s :=
 

> VariantParse( s, "%c", 'locale' = "de" );
 

Typesetting:-mrow(Typesetting:-mi(