From f334720c88c8c29e871753921e07322439aa5264 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Fri, 22 Apr 2022 18:32:57 +0200 Subject: [PATCH] Update date --- date.apln | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/date.apln b/date.apln index 6e28373..3bfd7af 100644 --- a/date.apln +++ b/date.apln @@ -4,7 +4,7 @@ info←⊃parse⍣≡info ⍺ ⍵ ⍝ Parse all we can ⍝ At this point, we may not have all information, so we need to fix that info←fixSecond fixMinute fixHour fixDay fixMonth fixYear info - 1⎕DT⊂,↑6↑info ⍝ convert the year, month, day, hour, minute, second to DDN + 1 ⎕DT⊂,↑6↑info ⍝ convert the year, month, day, hour, minute, second to DDN } parse←{ (info format str)←⍵ @@ -12,7 +12,7 @@ format startsWith⊂'YYYY':4(4000∘readNum)update 1⊢⍵ format startsWith⊂'YY':2(0 2000+99∘readNum)update 1⊢⍵ format startsWith'MMMM' 'Mmmm' 'mmmm' '_mmm':4(0∘readMonth)update 2⊢⍵ - format startsWith'MMM' 'Mmm' 'mmm' '_mm':3(1∘readMonth)update 2⊢⍵ + format startsWith'MMM' 'Mmm' 'mmm' '_mm':3(1∘readMonth)update 2⊢⍵ format startsWith'MM' '_M':2(12∘readNum)update 2⊢⍵ format startsWith⊂,'M':1(12∘readNum)update 2⊢⍵ format startsWith'DDDD' 'Dddd' 'dddd' '_ddd':4(0∘readDay)update 7⊢⍵ @@ -71,11 +71,32 @@ ⍺:3 d ⍝ ⍺=1 means short form lengths[d]d } - ⍝ Below are all the fixup functions - fixYear←{} - fixMonth←{} - fixDay←{} - fixHour←{} - fixMinute←{} - fixSecond←{} + ⍝ Below are all the fixup functions. If a value is present at the place + ⍝ we want to fix, the function doesn't change anything. + ⍝ Otherwise they use the most precise information available to set the field. + ⍝ If no information is available, they just pick a valid value. + fixYear←{ + ⍵[1]≢⊂⍬:⍵ + (2022@1)⍵ + } + fixMonth←{ + ⍵[2]≢⊂⍬:⍵ + (1@2)⍵ + } + fixDay←{ + ⍵[3]≢⊂⍬:⍵ + (1@3)⍵ + } + fixHour←{ + ⍵[4]≢⊂⍬:⍵ + (0@4)⍵ + } + fixMinute←{ + ⍵[5]≢⊂⍬:⍵ + (0@5)⍵ + } + fixSecond←{ + ⍵[6]≢⊂⍬:⍵ + (0@6)⍵ + } :EndNamespace -- 2.45.2