]> git.plutz.net Git - confetti/commitdiff
introduce localised date parsing
authorPaul Hänsch <paul@plutz.net>
Thu, 4 Feb 2021 21:06:56 +0000 (22:06 +0100)
committerPaul Hänsch <paul@plutz.net>
Thu, 4 Feb 2021 21:06:56 +0000 (22:06 +0100)
cards/new_card.sh
l10n.sh

index 1e37b7001af3c84a86d25409cdc8e81bc3e272ed..0273a2cb44ac481c2c6f7554e3e3782a855be3a0 100755 (executable)
@@ -39,6 +39,14 @@ IFS='|' read -r date fn ln bmonth byear tel tcell junk1 email junk2 note <<-EOF
 [ ${#byear} = 2 ] && byear="20$byear"
 [ ${#bmonth} = 1 ] && bmonth="0$bmonth"
 
+mn=""
+case $fn in
+  *\ *)
+    mn="${fn#* }"
+    fn="${fn%% *}"
+    ;;
+esac
+
 mkdir -p "${_DATA}/lock/vcard/"
 lockdir="${_DATA}/lock/vcard/${card}/"
 lockfile=${lockdir}/${SESSION_ID}
@@ -47,13 +55,13 @@ if mkdir "$lockdir"; then
   cat >"$lockfile" <<-EOF
        BEGIN:VCARD
        VERSION:4.0
-       N:$(vcf_escape "$ln");$(vcf_escape "$fn");;;
-       FN:$(vcf_escape "$fn $ln")
-       BDAY:$(vcf_escape "${byear}-${bmonth}-01")
+       N:$(vcf_escape "$ln" "$fn" "$mn" "" "")
+       FN:$(vcf_escape "${fn}${mn:+ }${mn} ${ln}")
+       BDAY:$(parse_date "${byear}-${bmonth}-01")
        TEL:$(vcf_escape "$tel")
        TEL;TYPE=CELL:$(vcf_escape "$tcell")
        EMAIL:$(vcf_escape "$email")
-       X-ZACK-JOINDATE:$(vcf_escape "$date")
+       X-ZACK-JOINDATE:$(parse_date "$date")
        ADR:
        NOTE:$(vcf_escape "$note")
        UID:${uid}
diff --git a/l10n.sh b/l10n.sh
index 361542e76718d4d07c6c4ee985e0f3a109dcbb17..c53cdd386197b8701ece0392cc85336ac38f4438 100755 (executable)
--- a/l10n.sh
+++ b/l10n.sh
@@ -115,6 +115,7 @@ l10n_global() {
 
     # UI Labels Special
     course_attendance) printf %s "Kurs&shy;teil&shy;nahme";;
+    vcf_seed_label) printf "Anmeld.    Vorn.   Nachn.  Geb. Monat      Geb. Jahr       Tel.    Mobil   ()      EMail   ()      Notiz";;
   
     gender_none) printf %s "keine Angabe";;
     gender_female) printf %s "Weiblich";;
@@ -156,3 +157,20 @@ l10n_time() {
     s;December;De\&shy\;zem\&shy\;ber;g;       s;Dec\.;Dez.;g;
   '
 }
+
+parse_date() {
+  [ $# -eq 0 ] && read -r date || date="$*"
+
+  case $date in
+    *[0-9].*[0-9].*[0-9])
+      d="${date%%.*}"
+      y="${date##*.}"
+      m="${date%.*}"
+      m="${m#*.}"
+      [ $y -lt 100 ] && y="$((y + 2000))"
+      date -d "$(printf '%04i-%02i-%02i' "$y" "$m" "$d")" +%F
+      ;;
+    *) date -d "$date" +%F
+      ;;
+  esac
+}