From patchwork Tue Apr 14 09:31:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 11487131 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46E45174A for ; Tue, 14 Apr 2020 09:32:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CAF22074D for ; Tue, 14 Apr 2020 09:32:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QnTirIB0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437666AbgDNJcI (ORCPT ); Tue, 14 Apr 2020 05:32:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437642AbgDNJcG (ORCPT ); Tue, 14 Apr 2020 05:32:06 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 451FBC0A3BD0 for ; Tue, 14 Apr 2020 02:32:05 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id g2so4460133plo.3 for ; Tue, 14 Apr 2020 02:32:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lJ8FltyKwypoT+d30kK9KAIRI2qGdyfQpWwNedrVc5E=; b=QnTirIB0UCUsDPMj6wEqgVUphFywDRMsrYIUHOBiLj9A8O3ZUXwIuZErwRTN6CZ4ga Dmg2ofNGmUw+DhY3AmZ9fM0qQffUb7icNdz99G/oSs3v+XoWINaHi34vo/c9mqQW2b1z 2Ih7s8aapolD7Zb47sAYhDhaUJBLPbFwae8dsjwT8dgNlOeT0wZcvHyPgl7Tm5s9J7Hn cXOu2kIocPXomD4H7KahFx73Bq62T7TyJqbOHBqM3ZlcE7jr+5nD5MdgTLnLvjd0C1fK jixKXCsfcH7zfUEtN/m8AdB75KHSmfEIlBPHgxEJpTjn8B2IeAXgG1VWkJhsjSfPAT/W +iBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lJ8FltyKwypoT+d30kK9KAIRI2qGdyfQpWwNedrVc5E=; b=g8F9TH66EMzXqYTlkNXiArOVLYeEwS8+Rg4HzMFpHbKXWW2+QyE6U86sPodztKP3ge NjNZKtWufzNF8yBfjJSE9XP/qlcyLSYB27SLdb17gNg3wtJra3XjDxb3qPm7QpszUsUR I9xKeFamzIDkkaJI6NEFf00iHWAoXBVCW7N34IOLsF/WVYlH+LHPeCK3K0PhrRzLtU2Y Gn32K1z91SdafllV4qa9uHkyIgYas8LUEdFdEgKI1/SDEy5dXDBafvLvt6SrRBJxyKD2 IrF25opbwr68DrI20a9MhhVvtUDJyGupPZk4h5v0NXJT3dB1IIKmXiNy/DN6jzDNNe99 PvHA== X-Gm-Message-State: AGi0PuZmDNxOdK+Ws463xVppB4uiruFsbGNYNMgDmeKT+PsFCD1+76wS B/lIh53H2+qf1mhxOuuW3UZafax4 X-Google-Smtp-Source: APiQypKF2VhbPd+3WplSJhb9//yZiy5Fkv+l0bpJH0WGBM9hA8hrI/yHumgfT1pJ5/YHUy7/Dry6Pg== X-Received: by 2002:a17:90a:19ca:: with SMTP id 10mr5404222pjj.23.1586856724547; Tue, 14 Apr 2020 02:32:04 -0700 (PDT) Received: from localhost.localdomain ([2402:800:6375:207b:be21:746a:7a56:9d4d]) by smtp.gmail.com with ESMTPSA id mu15sm11881506pjb.30.2020.04.14.02.32.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Apr 2020 02:32:04 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , "Brian M . Carlson" Subject: [PATCH 1/2] date.c: allow fractional second part of ISO-8601 Date: Tue, 14 Apr 2020 16:31:54 +0700 Message-Id: <45676f4a7d001dbd25bbae531cc2ae5fc53936bb.1586856398.git.congdanhqx@gmail.com> X-Mailer: git-send-email 2.26.0.485.g518673e55f In-Reply-To: References: <20200414000324.GA2751707@camp.crustytoothpaste.net> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org git-commit(1) says ISO-8601 is one of our supported date format. However, we only support RFC-3339 date format. We can either: - Update documentation from ISO-8601 to RFC-3339 - Add full support for ISO-8601 This series will try to add full support for ISO-8601. Reported-by: Brian M. Carlson Signed-off-by: Đoàn Trần Công Danh --- date.c | 2 ++ t/t0006-date.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/date.c b/date.c index b0d9a8421d..2f37397beb 100644 --- a/date.c +++ b/date.c @@ -556,6 +556,8 @@ static int match_multi_number(timestamp_t num, char c, const char *date, case ':': if (num3 < 0) num3 = 0; + else if (*end == '.' && isdigit(end[1])) + strtol(end + 1, &end, 10); if (num < 25 && num2 >= 0 && num2 < 60 && num3 >= 0 && num3 <= 60) { tm->tm_hour = num; tm->tm_min = num2; diff --git a/t/t0006-date.sh b/t/t0006-date.sh index d9fcc829a9..05c914a200 100755 --- a/t/t0006-date.sh +++ b/t/t0006-date.sh @@ -81,6 +81,7 @@ check_parse 2008-02 bad check_parse 2008-02-14 bad check_parse '2008-02-14 20:30:45' '2008-02-14 20:30:45 +0000' check_parse '2008-02-14 20:30:45 -0500' '2008-02-14 20:30:45 -0500' +check_parse '2008-02-14 20:30:45.019-04:00' '2008-02-14 20:30:45 -0400' check_parse '2008-02-14 20:30:45 -0015' '2008-02-14 20:30:45 -0015' check_parse '2008-02-14 20:30:45 -5' '2008-02-14 20:30:45 +0000' check_parse '2008-02-14 20:30:45 -5:' '2008-02-14 20:30:45 +0000' From patchwork Tue Apr 14 09:31:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 11487135 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 616D314B4 for ; Tue, 14 Apr 2020 09:32:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48A3B206D5 for ; Tue, 14 Apr 2020 09:32:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nq6kRIwQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437669AbgDNJcK (ORCPT ); Tue, 14 Apr 2020 05:32:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437663AbgDNJcG (ORCPT ); Tue, 14 Apr 2020 05:32:06 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 986A0C0A3BDC for ; Tue, 14 Apr 2020 02:32:06 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id t16so627722plo.7 for ; Tue, 14 Apr 2020 02:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JEv5A2mAE/aimDjsayWVyzZLCGC3q2anvP46IfXez7Q=; b=nq6kRIwQ3pw7++cuo7DlkuqgyNLBHV+WD+km1E6AxajRbuABd+YWfM5+cUEgmzdr4g DtRbIZTtwNs+Gem9GYKKKOLq2p3H6Db1rQoqCphtDWp35o5f38GSE150ciAVp+HGV58J oi8mHMXodK8Vet9MiMpeSdHq2mP0Fw1iYxeD2j1bWKD0r005hpd5qmEr5eu1Cnai6U39 XpbfPf+lvLcFSW6T+jBMo6MeJbKjSM8gBoCE7fPCivAtW/HBGjNVEOx57DZd6lf+xdmq yE1LBc5qkgSOfP2FPGAZBPgH4SihE4i8uZfGOjzy3kWfgeq1fP2xKtDjEb5eMWgSnTXc PhxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JEv5A2mAE/aimDjsayWVyzZLCGC3q2anvP46IfXez7Q=; b=stWP/tRlwRbRCIwDDGOrBFC32y+6dTgMH6rOjr+N4BM3yqA3Ibf6EV25js9nTsDwj/ FNC9T8Vd5vu72tgo+siKsemFQCcJIEZO7OLvn2NAXq2zd+TgNddqcTZk5a6lgCYv2O3K 1Y5QNAcEjr//WYtditHr/5fXnPdG/G8Y0gGnNeZ+dsWX7DVHfJvVT50Xqdx5SgnDcKv8 4jtXkbt1Pw+AKEcVnZbp0Z11wLvSlDvMWLT/GNPCEPpNhUNkfQTgjXp2LRM7Sx9k1+pq rJ9q3FaMEKPGoPAz6GmrjDE4KjXJSFZes3Se+YwmFnjxMtGq2QCjp2NaEnkH6y6GejFE xWPA== X-Gm-Message-State: AGi0PuZzyvbHiVHUrfeLqsLFZN9ayh66qkR8z1c69AMRIT/eq6/mbORU V0ncOJXjaSPATjYZyh8/M3rIPEck X-Google-Smtp-Source: APiQypLg301XatsbLBcXBU0836Y1HJxkwhvc9IP/NR1OoS8+n9sTzWU1yz+z92n/2pIH5mTVk5+fOA== X-Received: by 2002:a17:90a:a40b:: with SMTP id y11mr27966386pjp.130.1586856725977; Tue, 14 Apr 2020 02:32:05 -0700 (PDT) Received: from localhost.localdomain ([2402:800:6375:207b:be21:746a:7a56:9d4d]) by smtp.gmail.com with ESMTPSA id mu15sm11881506pjb.30.2020.04.14.02.32.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Apr 2020 02:32:05 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= Subject: [PATCH 2/2] date.c: allow compact version of ISO-8601 datetime Date: Tue, 14 Apr 2020 16:31:55 +0700 Message-Id: <06e62c58d5accad7bbebbc51f9fb38fda83a73f6.1586856398.git.congdanhqx@gmail.com> X-Mailer: git-send-email 2.26.0.485.g518673e55f In-Reply-To: References: <20200414000324.GA2751707@camp.crustytoothpaste.net> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Đoàn Trần Công Danh --- date.c | 18 ++++++++++++++++++ t/t0006-date.sh | 3 +++ 2 files changed, 21 insertions(+) diff --git a/date.c b/date.c index 2f37397beb..e02d8e191a 100644 --- a/date.c +++ b/date.c @@ -666,6 +666,24 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt n++; } while (isdigit(date[n])); + /* 8 digits, compact style of ISO-8601's date: YYYYmmDD */ + if (n == 8) { + tm->tm_year = num / 10000 - 1900; + tm->tm_mon = (num % 10000) / 100 - 1; + tm->tm_mday = num % 100; + return n; + } + + /* 6 digits, compact style of ISO-8601's time: HHMMSS */ + if (n == 6) { + tm->tm_hour = num / 10000; + tm->tm_min = (num % 10000) / 100; + tm->tm_sec = num % 100; + if (*end == '.' && isdigit(end[1])) + strtoul(end + 1, &end, 10); + return end - date; + } + /* Four-digit year or a timezone? */ if (n == 4) { if (num <= 1400 && *offset == -1) { diff --git a/t/t0006-date.sh b/t/t0006-date.sh index 05c914a200..eeb11070a6 100755 --- a/t/t0006-date.sh +++ b/t/t0006-date.sh @@ -81,6 +81,9 @@ check_parse 2008-02 bad check_parse 2008-02-14 bad check_parse '2008-02-14 20:30:45' '2008-02-14 20:30:45 +0000' check_parse '2008-02-14 20:30:45 -0500' '2008-02-14 20:30:45 -0500' +check_parse '20080214T203045-04:00' '2008-02-14 20:30:45 -0400' +check_parse '20080214T203045 -04:00' '2008-02-14 20:30:45 -0400' +check_parse '20080214T203045.019-04:00' '2008-02-14 20:30:45 -0400' check_parse '2008-02-14 20:30:45.019-04:00' '2008-02-14 20:30:45 -0400' check_parse '2008-02-14 20:30:45 -0015' '2008-02-14 20:30:45 -0015' check_parse '2008-02-14 20:30:45 -5' '2008-02-14 20:30:45 +0000'