From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id OHBuOdTjGGIc8QAAgWs5BA (envelope-from ) for ; Fri, 25 Feb 2022 15:12:36 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 4P89MtTjGGLZaQEAG6o9tA (envelope-from ) for ; Fri, 25 Feb 2022 15:12:36 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6EA2F21635 for ; Fri, 25 Feb 2022 15:12:36 +0100 (CET) Received: from localhost ([::1]:38906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nNbKk-0002uO-Go for larch@yhetil.org; Fri, 25 Feb 2022 09:12:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nNaY8-0003gA-4W for emacs-orgmode@gnu.org; Fri, 25 Feb 2022 08:22:21 -0500 Received: from [2a00:1450:4864:20::433] (port=35607 helo=mail-wr1-x433.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nNaY6-0002PZ-36 for emacs-orgmode@gnu.org; Fri, 25 Feb 2022 08:22:19 -0500 Received: by mail-wr1-x433.google.com with SMTP id b5so4536810wrr.2 for ; Fri, 25 Feb 2022 05:22:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SDI9005KmB9dGj9EEsev9XRTsv6F1NZVFHozHdKEM/U=; b=mWrKwg6gKUHuk4J5UgBKWGN2DAzdIgN0PAFkfT/cyarFklMH+mMKbDV81Zh36/oNto GlRsNVRnsFTQXLsRNvOV4EjZTK3aaV++msClKtTpn4breNcnLXW8henjZRcCy3feymJ4 oVReG8PnvU10Xc8FbUygp9/HxBpR9cX5742w1TkW+yfUSMDD9Ia+ITd0shdKDWfFCgso EfaxUFSsL2kUyniX0QWoYpOsSahiZR7PxvVF9aZx2sHwe2TxDhEUjBamOG+popFMsdRI 2PzkRlUiJIHgj6R5SjMEOm/XGu8PskcsD9MIjUtebuwiIFZZYGhG1s3FTqhSLVeGfj1f mdBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SDI9005KmB9dGj9EEsev9XRTsv6F1NZVFHozHdKEM/U=; b=1u0gYFfcFHZ7Jer3PjZa/Bk5wZIwilPz7oAOLYOexM6chJHjkbT1e7bb4HeDNxChjk ML6qI0rBugEAvG5/bNpn92GqAaAJKnJ31cT0Us8IB/aYAZaV723ImvnhPTeKY4oAle2z JNkdKdVEfLDhTk614yE55QOz1sW42QCcMSdyWE3Osh7kQix6E/QF+WsTRXm6roarIn8m X1p3E7wfbiZafz85EpM6bxAMfoQpAEVq4d/6HHcX3i8VWMJbw/CWFTkal0DijPKuuegb CtZl3e8ui0E4Bwvg3C8q2y2w1gXRqvc0ed9IW3vjHVhYK2AfCGMDQR+4GINnFLvHEC44 oMrw== X-Gm-Message-State: AOAM532GYoBtRZXEBM6T3KR5WvUCGxVhcslmxraL7c8+FVDjcC8CXh2w 6nOVy3QN4duSoFtXKDumh7tI9IbeAJI= X-Google-Smtp-Source: ABdhPJw43/cpk0Q0BTRlB3m2rNYyPmuKTx91LQiwS9G++i1Q7EhESGXICOGuzN7XS54ZmElRq1DdCg== X-Received: by 2002:adf:edc4:0:b0:1ee:27de:4b04 with SMTP id v4-20020adfedc4000000b001ee27de4b04mr5248773wro.117.1645795335793; Fri, 25 Feb 2022 05:22:15 -0800 (PST) Received: from localhost.localdomain ([2001:718:1e03:ffc2:3876:2831:dbc1:146b]) by smtp.gmail.com with ESMTPSA id o9-20020adfeac9000000b001e68d090023sm2332499wrn.68.2022.02.25.05.22.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 25 Feb 2022 05:22:15 -0800 (PST) From: David Lukes To: emacs-orgmode@gnu.org Subject: [PATCH] oc-basic.el: Better handling of CSL-JSON dates Date: Fri, 25 Feb 2022 14:21:44 +0100 Message-Id: <20220225132144.36513-1-dafydd.lukes@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::433 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=dafydd.lukes@gmail.com; helo=mail-wr1-x433.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Lukes Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1645798356; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=SDI9005KmB9dGj9EEsev9XRTsv6F1NZVFHozHdKEM/U=; b=ENFJZdqylC1exzNKiiAqQ+GoTbYN8/rzpHIBmi5d4Ay+1zFuHoHQVEqRwKcHkR1ufCyZrs HaHJYCqhRE4CmclcRHR57zlcOLZx0+pmDlm8V1hq+JejMgKMycqZ0kLwNUbtTa9PBqHW+6 1XAUupSubYHM1Wjzq2CZVUV5ywMTnMGiMVp5CADK1b/zSSzDsOqW25+8Ze6t3giTvh2v3x aEyA7PwdYMr6sjPXuQskFNjraSWj0BZxzBbf55hYKvw+BKl/FYo47vuWf1NEgOChpL7lZi TgXHC3AZfmYDJNLy7DNf3v1Q0+BnuryisAsksLdaWaZQgXr9t35uA9VoetMvPw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1645798356; a=rsa-sha256; cv=none; b=t6jIh6vf7TN86t6zi8Yi4V9tOOmtX8J9D3swuuLiCxGJoUrjvVQ3pLz450Zl+iEskJcBR+ D0ZwmaKlvx1PsPv80x/ngTX39gnk0e04mivFrrjHpgkyoP1WOcQkg4ellMflgEGqbz0QvE 7X2P3pX0TaRMkRvwio3EVGXTw6oCuQtqZF+6RbcJuHS7Ns5v2bYXbu09M3FXWiwZ/2+CJR JzKOi8ShAyp9HNsFBem6dA4wp03V9jVFaZ01WnbjuzmuDLOgSdBfvViNRcCSxhjXPsJODA KgwlM+jrlDqjNKB15NOczj/UnJAqyz+LKzxETuCBYG1nfqPCzZyo+fLoM1+S9Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mWrKwg6g; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -5.83 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mWrKwg6g; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 6EA2F21635 X-Spam-Score: -5.83 X-Migadu-Scanner: scn0.migadu.com X-TUID: Wy0VNbdMzv0p * lisp/oc-basic.el (org-cite-basic--parse-json): Make date-parsing and year extraction more resilient. Provide more informative errors when it fails. A string-based date is not only indicated by the key 'raw, but also possibly by the key 'literal. String-based dates come in various formats, not necessarily yyyy-mm-dd. So extracting the first sequence of 4 digits is arguably a better heuristic for getting the publication year than splitting the string on - and getting the car of that. On error, include `value' in the message, which contains the original value with actionable information, whereas the previously included `date' is always nil in that case. TINYCHANGE --- lisp/oc-basic.el | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lisp/oc-basic.el b/lisp/oc-basic.el index d82406aff..81b7e4471 100644 --- a/lisp/oc-basic.el +++ b/lisp/oc-basic.el @@ -178,21 +178,29 @@ Return a hash table with citation references as keys and fields alist as values. " and "))) ('issued ;; Date are expressed as an array - ;; (`date-parts') or a "string (`raw'). - ;; In both cases, extract the year and - ;; associate it to `year' field, for - ;; compatibility with BibTeX format. + ;; (`date-parts') or a "string (`raw' + ;; or `literal'). In both cases, + ;; extract the year and associate it + ;; to `year' field, for compatibility + ;; with BibTeX format. (let ((date (or (alist-get 'date-parts value) + (alist-get 'literal value) (alist-get 'raw value)))) (cons 'year (cond ((consp date) (caar date)) ((stringp date) - (car (split-string date "-"))) + (replace-regexp-in-string + (rx + (minimal-match (zero-or-more anything)) + (group-n 1 (repeat 4 digit)) + (zero-or-more anything)) + (rx (backref 1)) + date)) (t (error "Unknown CSL-JSON date format: %S" - date)))))) + value)))))) (_ (cons field value)))) item) -- 2.34.1