eyeseast / python-frontmatter

Parse and manage posts with YAML (or other) frontmatter
http://python-frontmatter.rtfd.io
MIT License
329 stars 43 forks source link

Date values are being converted to datetime objects #102

Closed lolbat closed 1 year ago

lolbat commented 1 year ago

I am writing a short utility to check the values of some of the keys in posts I am writing for the Hugo ssg.

Each post has a date key with the date value stored as an RFC3339 format date

date: 2022-12-06T09:05:28-06:00

When I read the date key in the code appears to be converting it to a datetime object

2022-12-06 09:05:28-06:00

and when that gets converted back into a string the date isn't in the correct format.

Would it be possible to add a load option that didn't convert the dates? I have hacked a fix together to recreate the proper date but it would be nice to have them left as strings.

eyeseast commented 1 year ago

This may be a YAML issue. What happens when you do the same roundtrip with PyYAML alone?

lolbat commented 1 year ago

Let me write a test and get back to you

lolbat commented 1 year ago

As you thought, it is the YAML library

{'title': 'Learning a new language', 'date': datetime.datetime(2023, 3, 29, 8, 58, 50, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=64800))), 'draft': False, 'tags': ['Python', 'Hugo']}

lolbat commented 1 year ago

It also converts all of the truthy text to booleans as well.