Reputation: 739
I've got a Django app that needs to take a list of multiple datetimes and print out a simple string that explains what the pattern is.
Example:
With 3 datetime instances for Monday, Wednesday, and Friday at 3pm, the simple output would be something like Monday, Wednesday, Friday at 3:00pm
With 3 datetime instances of the 4th of every month, the output would be The 4th of every month
I searched and didn't find anything built into Python or Django, but does anyone know of any open source scripts that can do something similar? The only way I would know of doing it is manually trying to match the patterns of the list of datetimes and that sounds like a lot of if ... else ... statements.
Upvotes: 1
Views: 179
Reputation: 21243
As per your need you have to use Python Calendar
module to iterate over the weekdays or days or the month. It provide the functions to read on specific day of month or week.
Upvotes: 0
Reputation: 249193
It sounds like something that is fundamentally "business logic." For example, if the dates happen to all be Easter on consecutive years, do you expect that to be picked up? What about if they are all the last day of Hanukkah? This isn't likely to be something that's handled by a language or library directly--you'll need to write the logic and rules yourself, I imagine. There's definitely room to be innovative here--think about how you can express the rules in a uniform way...look at the existing timezone database and other such existing software for inspiration (or warnings of what to avoid!).
Upvotes: 2