From 5d52b5c71310d367a240991e6d3ce82fa1c742ab Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Thu, 4 Feb 2021 22:06:56 +0100 Subject: [PATCH] introduce localised date parsing --- cards/new_card.sh | 16 ++++++++++++---- l10n.sh | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/cards/new_card.sh b/cards/new_card.sh index 1e37b70..0273a2c 100755 --- a/cards/new_card.sh +++ b/cards/new_card.sh @@ -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 361542e..c53cdd3 100755 --- a/l10n.sh +++ b/l10n.sh @@ -115,6 +115,7 @@ l10n_global() { # UI Labels Special course_attendance) printf %s "Kurs­teil­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\­\;zem\­\;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 +} -- 2.39.2