Skip to content

Commit

Permalink
Support bare YAML dates and times. Fixes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
kislyuk committed Dec 27, 2017
1 parent f88017c commit c01a4b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,16 @@ def test_datetimes(self):
self.assertEqual(self.run_yq("- 2016-12-20T22:07:36Z\n", ["."]), "")
self.assertEqual(self.run_yq("- 2016-12-20T22:07:36Z\n", ["-y", "."]), "- '2016-12-20T22:07:36'\n")

self.assertEqual(self.run_yq("2016-12-20", ["."]), "")
self.assertEqual(self.run_yq("2016-12-20", ["-y", "."]), "'2016-12-20'\n")

@unittest.expectedFailure
def test_times(self):
"""
Timestamps are parsed as sexagesimals in YAML 1.1 but not 1.2. No PyYAML support for YAML 1.2 yet. See issue 10
"""
self.assertEqual(self.run_yq("11:12:13", ["."]), "")
self.assertEqual(self.run_yq("11:12:13", ["-y", "."]), "'11:12:13'\n")

if __name__ == '__main__':
unittest.main()
4 changes: 2 additions & 2 deletions yq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import os, sys, argparse, subprocess, json
from collections import OrderedDict
from datetime import datetime
from datetime import datetime, date, time
import yaml
from .version import __version__

Expand All @@ -30,7 +30,7 @@ class OrderedDumper(yaml.SafeDumper):

class JSONDateTimeEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, datetime):
if isinstance(o, (datetime, date, time)):
return o.isoformat()
return json.JSONEncoder.default(self, o)

Expand Down

0 comments on commit c01a4b3

Please sign in to comment.