-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4031bc7
Showing
20 changed files
with
731 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please refer to <https://unlicense.org> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Utilities for formatting `Date`s as `Text` in the [Dhall](https://dhall-lang.org/) | ||
configuration language. | ||
|
||
## Usage example | ||
|
||
```dhall | ||
let DF = ./src/package.dhall | ||
let F = DF.Formats | ||
|
||
in | ||
[DF.format F.`MM.DD.YYYY` 1991-09-17 | ||
,DF.format F.`the Dth of MMMM, YYYY` 1990-04-01 | ||
,DF.format (DF.mask "D@MMMM[YY]") 1970-01-01 | ||
] | ||
``` | ||
|
||
evaluates to | ||
|
||
```dhall | ||
[ "09.17.1991", "the 1st of April, 1990", "1@January[70]" ] | ||
``` | ||
|
||
## Available formats | ||
|
||
The formats provided by the library all live in `./src/Formats/package.dhall`. | ||
|
||
It is easy to implement your own format; see the source code of the existing | ||
formats and proceed analogously. You may also use `./src/mask.dhall` to create | ||
a simple format using a `Text` mask. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{-| | ||
Year, month and day represented as `Text` values. Values of this type | ||
are not meant to be constructed by hand. You should use [`./parse.dhall`](./parse.dhall.html) | ||
instead. If you decide to construct them manually, it is up to you to ensure | ||
that the data is correct. | ||
-} | ||
let DateComponents = { year : Text, month : Text, day : Text } in DateComponents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let DateComponents = | ||
missing | ||
sha256:838b1cd41f59c2bf50fe2785453756dc54da24b76576752ec2bf29973d0a926b | ||
? ./DateComponents.dhall | ||
|
||
let Format = DateComponents → Text | ||
|
||
in Format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
let Days = | ||
{ _01 : Text | ||
, _02 : Text | ||
, _03 : Text | ||
, _04 : Text | ||
, _05 : Text | ||
, _06 : Text | ||
, _07 : Text | ||
, _08 : Text | ||
, _09 : Text | ||
, _10 : Text | ||
, _11 : Text | ||
, _12 : Text | ||
, _13 : Text | ||
, _14 : Text | ||
, _15 : Text | ||
, _16 : Text | ||
, _17 : Text | ||
, _18 : Text | ||
, _19 : Text | ||
, _20 : Text | ||
, _21 : Text | ||
, _22 : Text | ||
, _23 : Text | ||
, _24 : Text | ||
, _25 : Text | ||
, _26 : Text | ||
, _27 : Text | ||
, _28 : Text | ||
, _29 : Text | ||
, _30 : Text | ||
, _31 : Text | ||
} | ||
|
||
in Days |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
let Days = ../Days.dhall | ||
|
||
let shortEnglishOrdinals : Days = | ||
{ | ||
_01 = "1st" | ||
,_02 = "2nd" | ||
,_03 = "3rd" | ||
,_04 = "4th" | ||
,_05 = "5th" | ||
,_06 = "6th" | ||
,_07 = "7th" | ||
,_08 = "8th" | ||
,_09 = "9th" | ||
,_10 = "10th" | ||
,_11 = "11th" | ||
,_12 = "12th" | ||
,_13 = "13th" | ||
,_14 = "14th" | ||
,_15 = "15th" | ||
,_16 = "16th" | ||
,_17 = "17th" | ||
,_18 = "18th" | ||
,_19 = "19th" | ||
,_20 = "20th" | ||
,_21 = "21st" | ||
,_22 = "22nd" | ||
,_23 = "23rd" | ||
,_24 = "24th" | ||
,_25 = "25th" | ||
,_26 = "26th" | ||
,_27 = "27th" | ||
,_28 = "28th" | ||
,_29 = "29th" | ||
,_30 = "30th" | ||
,_31 = "31st" | ||
} | ||
|
||
in shortEnglishOrdinals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
let Months = | ||
{ _01 : Text | ||
, _02 : Text | ||
, _03 : Text | ||
, _04 : Text | ||
, _05 : Text | ||
, _06 : Text | ||
, _07 : Text | ||
, _08 : Text | ||
, _09 : Text | ||
, _10 : Text | ||
, _11 : Text | ||
, _12 : Text | ||
} | ||
|
||
in Months |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
let Months = ../Months.dhall | ||
|
||
let fullEnglishMonthNames : Months = | ||
{ | ||
_01 = "January" | ||
,_02 = "February" | ||
,_03 = "March" | ||
,_04 = "April" | ||
,_05 = "May" | ||
,_06 = "June" | ||
,_07 = "July" | ||
,_08 = "August" | ||
,_09 = "September" | ||
,_10 = "October" | ||
,_11 = "November" | ||
,_12 = "December" | ||
} | ||
|
||
|
||
in fullEnglishMonthNames |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
let Months = ../Months.dhall | ||
|
||
let shortEnglishMonthNames : Months = | ||
{ | ||
_01 = "Jan" | ||
,_02 = "Feb" | ||
,_03 = "Mar" | ||
,_04 = "Apr" | ||
,_05 = "May" | ||
,_06 = "Jun" | ||
,_07 = "Jul" | ||
,_08 = "Aug" | ||
,_09 = "Sep" | ||
,_10 = "Oct" | ||
,_11 = "Nov" | ||
,_12 = "Dec" | ||
} | ||
|
||
in shortEnglishMonthNames |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
let applyAll | ||
: List (Text → Text) → Text → Text | ||
= λ(fs : List (Text → Text)) → | ||
λ(t : Text) → | ||
List/fold | ||
(Text → Text) | ||
fs | ||
Text | ||
(λ(f : Text → Text) → λ(s : Text) → f s) | ||
t | ||
|
||
in applyAll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{-| | ||
Drops a leading `0` character from a `Text` value. The `Text` value should not | ||
contain the character `^`. | ||
Meant to be used with day/month components of a date. | ||
-} | ||
let dropLeading0 | ||
: Text → Text | ||
= λ(t : Text) → Text/replace "^" "" (Text/replace "^0" "" "^${t}") | ||
|
||
let example0 = assert : dropLeading0 "01" ≡ "1" | ||
|
||
let example1 = assert : dropLeading0 "10" ≡ "10" | ||
|
||
in dropLeading0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{-| | ||
Converts year in the YYYY format to YY (drops first two digits). | ||
-} | ||
let dropTwoFirstDigits | ||
: Text → Text | ||
= λ(s : Text) → | ||
let dropPrefixDigit | ||
: Text → Text | ||
= λ(t : Text) → | ||
Text/replace | ||
"^0" | ||
"" | ||
( Text/replace | ||
"^1" | ||
"" | ||
( Text/replace | ||
"^2" | ||
"" | ||
( Text/replace | ||
"^3" | ||
"" | ||
( Text/replace | ||
"^4" | ||
"" | ||
( Text/replace | ||
"^5" | ||
"" | ||
( Text/replace | ||
"^6" | ||
"" | ||
( Text/replace | ||
"^7" | ||
"" | ||
( Text/replace | ||
"^8" | ||
"" | ||
(Text/replace "^9" "" "^${t}") | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
|
||
in dropPrefixDigit (dropPrefixDigit s) | ||
|
||
let example0 = assert : dropTwoFirstDigits "2024" ≡ "24" | ||
|
||
in dropTwoFirstDigits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
let Days = | ||
missing | ||
sha256:ce1bd0a8eb935038500f51c3d8c64db3cba4b94c1010c24eb8421373190e8543 | ||
? ./Days.dhall | ||
|
||
let applyAll = | ||
missing | ||
sha256:35816a75ca591818e135c2df9aae7db623ebb338dc7b313c2b4342dddb1fe15d | ||
? ./applyAll.dhall | ||
|
||
let translateDay | ||
: Days → Text → Text | ||
= λ(days : Days) → | ||
applyAll | ||
[ Text/replace "01" days._01 | ||
, Text/replace "02" days._02 | ||
, Text/replace "03" days._03 | ||
, Text/replace "04" days._04 | ||
, Text/replace "05" days._05 | ||
, Text/replace "06" days._06 | ||
, Text/replace "07" days._07 | ||
, Text/replace "08" days._08 | ||
, Text/replace "09" days._09 | ||
, Text/replace "10" days._10 | ||
, Text/replace "11" days._11 | ||
, Text/replace "12" days._12 | ||
, Text/replace "13" days._13 | ||
, Text/replace "14" days._14 | ||
, Text/replace "15" days._15 | ||
, Text/replace "16" days._16 | ||
, Text/replace "17" days._17 | ||
, Text/replace "18" days._18 | ||
, Text/replace "19" days._19 | ||
, Text/replace "20" days._20 | ||
, Text/replace "21" days._21 | ||
, Text/replace "22" days._22 | ||
, Text/replace "23" days._23 | ||
, Text/replace "24" days._24 | ||
, Text/replace "25" days._25 | ||
, Text/replace "26" days._26 | ||
, Text/replace "27" days._27 | ||
, Text/replace "28" days._28 | ||
, Text/replace "29" days._29 | ||
, Text/replace "30" days._30 | ||
, Text/replace "31" days._31 | ||
] | ||
|
||
in translateDay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
let Months = | ||
missing | ||
sha256:f3d7d555826d119601250b62b7d0352729172c3f049da267dc10104fc4901459 | ||
? ./Months.dhall | ||
|
||
let applyAll = | ||
missing | ||
sha256:35816a75ca591818e135c2df9aae7db623ebb338dc7b313c2b4342dddb1fe15d | ||
? ./applyAll.dhall | ||
|
||
let translateMonth | ||
: Months → Text → Text | ||
= λ(months : Months) → | ||
applyAll | ||
[ Text/replace "01" months._01 | ||
, Text/replace "02" months._02 | ||
, Text/replace "03" months._03 | ||
, Text/replace "04" months._04 | ||
, Text/replace "05" months._05 | ||
, Text/replace "06" months._06 | ||
, Text/replace "07" months._07 | ||
, Text/replace "08" months._08 | ||
, Text/replace "09" months._09 | ||
, Text/replace "10" months._10 | ||
, Text/replace "11" months._11 | ||
, Text/replace "12" months._12 | ||
] | ||
|
||
in translateMonth |
Oops, something went wrong.