# HG changeset patch
# User Yuya Nishihara <y...@tcha.org>
# Date 1523627929 -32400
#      Fri Apr 13 22:58:49 2018 +0900
# Node ID 356d01cf53f693c0ff8dd9de49ba85037f57a048
# Parent  3b799d7e0865e9226ef1de1a858b6de08b612472
formatter: convert timestamp to int

Spotted while porting jsonchangeset printer to formatter. A timestamp may be
float type, but its meaningful part is just int.

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -144,7 +144,9 @@ class _nullconverter(object):
     @staticmethod
     def formatdate(date, fmt):
         '''convert date tuple to appropriate format'''
-        return date
+        # timestamp can be float, but the canonical form should be int
+        ts, tz = date
+        return (int(ts), tz)
     @staticmethod
     def formatdict(data, key, value, fmt, sep):
         '''convert dict or key-value pairs to appropriate dict format'''
diff --git a/tests/test-export.t b/tests/test-export.t
--- a/tests/test-export.t
+++ b/tests/test-export.t
@@ -165,7 +165,7 @@ Templated output to stdout:
   [
    {
     "branch": "default",
-    "date": [0.0, 0],
+    "date": [0, 0],
     "desc": "foo-0",
     "diff": "diff -r 000000000000 -r 871558de6af2 foo\n--- /dev/null\tThu Jan 
01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -0,0 +1,1 
@@\n+foo-0\n",
     "node": "871558de6af2e8c244222f8eea69b782c94ce3df",
@@ -181,7 +181,7 @@ Templated output to single file:
   [
    {
     "branch": "default",
-    "date": [0.0, 0],
+    "date": [0, 0],
     "desc": "foo-0",
     "diff": "diff -r 000000000000 -r 871558de6af2 foo\n--- /dev/null\tThu Jan 
01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -0,0 +1,1 
@@\n+foo-0\n",
     "node": "871558de6af2e8c244222f8eea69b782c94ce3df",
@@ -190,7 +190,7 @@ Templated output to single file:
    },
    {
     "branch": "default",
-    "date": [0.0, 0],
+    "date": [0, 0],
     "desc": "foo-1",
     "diff": "diff -r 871558de6af2 -r d1c9656e973c foo\n--- a/foo\tThu Jan 01 
00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,1 +1,2 
@@\n foo-0\n+foo-1\n",
     "node": "d1c9656e973cfb5aebd5499bbd2cb350e3b12266",
@@ -206,7 +206,7 @@ Templated output to multiple files:
   [
    {
     "branch": "default",
-    "date": [0.0, 0],
+    "date": [0, 0],
     "desc": "foo-0",
     "diff": "diff -r 000000000000 -r 871558de6af2 foo\n--- /dev/null\tThu Jan 
01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -0,0 +1,1 
@@\n+foo-0\n",
     "node": "871558de6af2e8c244222f8eea69b782c94ce3df",
@@ -218,7 +218,7 @@ Templated output to multiple files:
   [
    {
     "branch": "default",
-    "date": [0.0, 0],
+    "date": [0, 0],
     "desc": "foo-1",
     "diff": "diff -r 871558de6af2 -r d1c9656e973c foo\n--- a/foo\tThu Jan 01 
00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,1 +1,2 
@@\n foo-0\n+foo-1\n",
     "node": "d1c9656e973cfb5aebd5499bbd2cb350e3b12266",
diff --git a/tests/test-grep.t b/tests/test-grep.t
--- a/tests/test-grep.t
+++ b/tests/test-grep.t
@@ -58,7 +58,7 @@ simple JSON (no "change" field)
   $ hg grep -Tjson port
   [
    {
-    "date": [4.0, 0],
+    "date": [4, 0],
     "file": "port",
     "line_number": 1,
     "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c",
@@ -67,7 +67,7 @@ simple JSON (no "change" field)
     "user": "spam"
    },
    {
-    "date": [4.0, 0],
+    "date": [4, 0],
     "file": "port",
     "line_number": 2,
     "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c",
@@ -76,7 +76,7 @@ simple JSON (no "change" field)
     "user": "spam"
    },
    {
-    "date": [4.0, 0],
+    "date": [4, 0],
     "file": "port",
     "line_number": 3,
     "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c",
@@ -91,7 +91,7 @@ simple JSON without matching lines
   $ hg grep -Tjson -l port
   [
    {
-    "date": [4.0, 0],
+    "date": [4, 0],
     "file": "port",
     "line_number": 1,
     "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c",
@@ -119,7 +119,7 @@ all JSON
   [
    {
     "change": "-",
-    "date": [4.0, 0],
+    "date": [4, 0],
     "file": "port",
     "line_number": 4,
     "node": "914fa752cdea87777ac1a8d5c858b0c736218f6c",
@@ -129,7 +129,7 @@ all JSON
    },
    {
     "change": "+",
-    "date": [3.0, 0],
+    "date": [3, 0],
     "file": "port",
     "line_number": 4,
     "node": "95040cfd017d658c536071c6290230a613c4c2a6",
@@ -139,7 +139,7 @@ all JSON
    },
    {
     "change": "-",
-    "date": [2.0, 0],
+    "date": [2, 0],
     "file": "port",
     "line_number": 1,
     "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
@@ -149,7 +149,7 @@ all JSON
    },
    {
     "change": "-",
-    "date": [2.0, 0],
+    "date": [2, 0],
     "file": "port",
     "line_number": 2,
     "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
@@ -159,7 +159,7 @@ all JSON
    },
    {
     "change": "+",
-    "date": [2.0, 0],
+    "date": [2, 0],
     "file": "port",
     "line_number": 1,
     "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
@@ -169,7 +169,7 @@ all JSON
    },
    {
     "change": "+",
-    "date": [2.0, 0],
+    "date": [2, 0],
     "file": "port",
     "line_number": 2,
     "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
@@ -179,7 +179,7 @@ all JSON
    },
    {
     "change": "+",
-    "date": [2.0, 0],
+    "date": [2, 0],
     "file": "port",
     "line_number": 3,
     "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47",
@@ -189,7 +189,7 @@ all JSON
    },
    {
     "change": "+",
-    "date": [1.0, 0],
+    "date": [1, 0],
     "file": "port",
     "line_number": 2,
     "node": "8b20f75c158513ff5ac80bd0e5219bfb6f0eb587",
@@ -199,7 +199,7 @@ all JSON
    },
    {
     "change": "+",
-    "date": [0.0, 0],
+    "date": [0, 0],
     "file": "port",
     "line_number": 1,
     "node": "f31323c9217050ba245ee8b537c713ec2e8ab226",
diff --git a/tests/test-journal.t b/tests/test-journal.t
--- a/tests/test-journal.t
+++ b/tests/test-journal.t
@@ -147,7 +147,7 @@ Test that verbose, JSON, template and co
   [
    {
     "command": "up",
-    "date": [5.0, 0],
+    "date": [5, 0],
     "name": ".",
     "newhashes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
     "oldhashes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
@@ -155,7 +155,7 @@ Test that verbose, JSON, template and co
    },
    {
     "command": "up 0",
-    "date": [2.0, 0],
+    "date": [2, 0],
     "name": ".",
     "newhashes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
     "oldhashes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
@@ -163,7 +163,7 @@ Test that verbose, JSON, template and co
    },
    {
     "command": "commit -Aqm b",
-    "date": [1.0, 0],
+    "date": [1, 0],
     "name": ".",
     "newhashes": ["1e6c11564562b4ed919baca798bc4338bd299d6a"],
     "oldhashes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
@@ -171,7 +171,7 @@ Test that verbose, JSON, template and co
    },
    {
     "command": "commit -Aqm a",
-    "date": [0.0, 0],
+    "date": [0, 0],
     "name": ".",
     "newhashes": ["cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b"],
     "oldhashes": ["0000000000000000000000000000000000000000"],
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -715,49 +715,49 @@ List of all markers in JSON
   $ hg debugobsolete -Tjson
   [
    {
-    "date": [1339.0, 0],
+    "date": [1339, 0],
     "flag": 0,
     "metadata": {"user": "test"},
     "prednode": "1339133913391339133913391339133913391339",
     "succnodes": ["ca819180edb99ed25ceafb3e9584ac287e240b00"]
    },
    {
-    "date": [1339.0, 0],
+    "date": [1339, 0],
     "flag": 0,
     "metadata": {"user": "test"},
     "prednode": "1337133713371337133713371337133713371337",
     "succnodes": ["5601fb93a350734d935195fee37f4054c529ff39"]
    },
    {
-    "date": [121.0, 120],
+    "date": [121, 120],
     "flag": 12,
     "metadata": {"user": "test"},
     "prednode": "245bde4270cd1072a27757984f9cda8ba26f08ca",
     "succnodes": ["cdbce2fbb16313928851e97e0d85413f3f7eb77f"]
    },
    {
-    "date": [1338.0, 0],
+    "date": [1338, 0],
     "flag": 1,
     "metadata": {"user": "test"},
     "prednode": "5601fb93a350734d935195fee37f4054c529ff39",
     "succnodes": ["6f96419950729f3671185b847352890f074f7557"]
    },
    {
-    "date": [1338.0, 0],
+    "date": [1338, 0],
     "flag": 0,
     "metadata": {"user": "test"},
     "prednode": "ca819180edb99ed25ceafb3e9584ac287e240b00",
     "succnodes": ["1337133713371337133713371337133713371337"]
    },
    {
-    "date": [1337.0, 0],
+    "date": [1337, 0],
     "flag": 0,
     "metadata": {"user": "test"},
     "prednode": "cdbce2fbb16313928851e97e0d85413f3f7eb77f",
     "succnodes": ["ca819180edb99ed25ceafb3e9584ac287e240b00"]
    },
    {
-    "date": [0.0, 0],
+    "date": [0, 0],
     "flag": 0,
     "metadata": {"user": "test"},
     "parentnodes": ["6f96419950729f3671185b847352890f074f7557"],
@@ -1546,7 +1546,7 @@ only a subset of those are displayed (be
   $ hg debugobsolete --index --rev "3+7" -Tjson
   [
    {
-    "date": [0.0, 0],
+    "date": [0, 0],
     "flag": 0,
     "index": 1,
     "metadata": {"ef1": "1", "operation": "amend", "user": "test"},
@@ -1554,7 +1554,7 @@ only a subset of those are displayed (be
     "succnodes": ["d27fb9b066076fd921277a4b9e8b9cb48c95bc6a"]
    },
    {
-    "date": [0.0, 0],
+    "date": [0, 0],
     "flag": 0,
     "index": 3,
     "metadata": {"ef1": "1", "operation": "amend", "user": "test"},
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to