-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Use Babel's format_datetime
, not format_date
#6981
Conversation
I am using MkDocs-Material 9.5.15 and Babel 2.14.0. When setting the config value `blog.post_date_format: "yyyy-MM-dd hh:mm:ss"`, the blog plugin crashes during compilation with the error "date objects have no hour field". I believe this is occurring because the plugin provides a `datetime` to `babel.dates.format_date`, which upcasts it to a plain, timeless, `date`. Making this change to use `babel.dates.format_datetime` instead resolved the error and demonstrated expected behavior. While I recognize that it is likely uncommon for a blog to want to include sub-date timestamps in any of these fields, I believe that the current documentation, > The format string must adhere to babel's pattern syntax and should not contain whitespace implies that _any_ of Babel's pattern markers are acceptable here. I would consider > The format string must adhere to Babel's pattern syntax for calendar dates and should not contain whitespace to also be a sufficient fix for this case. ---- Thank you for your effort in creating this project; it has been a wonderful benefit to my team, and this is the first minor problem we've had in months of using it.
Thanks for the PR! It sounds legit, and should work, as we coerce all dates to datetimes anyway, but unfortunately you made the changes in the wrong place. You need to make changes in the Additionally, could you please provide a minimal reproduction here? Before we can consider merging a PR that fixes an error, we must first ensure that it actually is an error. This is also why, before creating an issue, we recommend to discuss changes with us. (info box) We cannot just change things without understanding their impact. However, in this case, you can attach the minimal reproduction which showcases the problem here. I hope you understand that with a project of this size, we have to have processes and we must ask our users to stick to them. Otherwise it would be unmanageable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
Of course! I apologize for the misplacement; I made the patch in my own app's dependency tree, and once it ran, replicated the change here. I will submit a correct commit and a before/after diagnostic after dinner. Thank you for the clear instruction! |
9.5.15-datetime-type-error.zip Current behavior:
After this change, the missing-attribute error goes away, and the site builds as expected. As a bonus, I have included a second bug in the reproduction zip: after this patch is applied, using a timezone marker in the metadata's date literal causes a comparison error:
I'm not sure what, if anything, to do about this. I would probably order my potential solution ideas roughly like this:
I hope I have followed your instructions sufficiently. I am not a fluent Python developer. Please let me know if there's anything else you need from me. |
While I have run |
I'm not sure what you're referring to, maybe the source maps? Those should be relative, at least they all are on my machine and in the repository. However, you can also only commit the contents of |
Thanks for providing the reproduction – looks good to me! |
I am using MkDocs-Material 9.5.15 and Babel 2.14.0. When setting the config value
blog.post_date_format: "yyyy-MM-dd hh:mm:ss"
, the blog plugin crashes during compilation with the error "date objects have no hour field".I believe this is occurring because the plugin provides a
datetime
tobabel.dates.format_date
, which upcasts it to a plain, timeless,date
. Making this change to usebabel.dates.format_datetime
instead resolved the error and demonstrated expected behavior.While I recognize that it is likely uncommon for a blog to want to include sub-date timestamps in any of these fields, I believe that the current documentation,
implies that any of Babel's pattern markers are acceptable here. I would consider
to also be a sufficient fix for this case.
Thank you for your effort in creating this project; it has been a wonderful benefit to my team, and this is the first minor problem we've had in months of using it.