Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dates (without times) and times (without dates) #10

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
long_description=open("README.rst").read(),
install_requires=[
"setuptools",
"PyYAML >= 3.11"
"ruamel.yaml >= 0.15.35"
],
tests_require=tests_require,
extras_require={"test": tests_require},
Expand Down
6 changes: 6 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,11 @@ 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")

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()
8 changes: 4 additions & 4 deletions yq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

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

class Parser(argparse.ArgumentParser):
Expand All @@ -19,7 +19,7 @@ def print_help(self):
print("\n".join(["usage: yq [options] <jq filter> [YAML file...]"] + yq_help[1:] + [""]))
try:
subprocess.check_call(["jq", "--help"])
except:
except Exception:
pass

class OrderedLoader(yaml.SafeLoader):
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)):
return o.isoformat()
return json.JSONEncoder.default(self, o)

Expand Down