How to convert "1 Jan 2020" or "2020-05-13" or "today" to a Date object?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to convert "1 Jan 2020" or "2020-05-13" or "today" to a Date object?

dbareis
Hi,

I have tried code similar to the following (with and without the modifier).

d = Date()
d.set(text='First of Jan',  modifier=Date.MOD_TEXTONLY)

If I display the str(d) I get "0000-00-00"

Maybe "set" is not the right way but there must be a way to correctly set up a Date() object from a user-defined text string (as long as the format is valid).

---
Thanks
Dennis


Mailtrack Sender notified by
Mailtrack 13/05/20, 02:49:19 pm


_______________________________________________
Gramps-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-devel
Reply | Threaded
Open this post in threaded view
|

Re: How to convert "1 Jan 2020" or "2020-05-13" or "today" to a Date object?

Steve Youngs

Hi Dennis

See https://github.com/gramps-project/gramps/blob/master/gramps/gen/lib/date.py for the Date class

See https://github.com/gramps-project/gramps/blob/master/gramps/gen/datehandler/_dateparser.py for the code to parse a date. This is the base class. There are language specific handlers in the same folder.

DateParser.parse(self, text) looks like it will be useful to you. Here's an example of it's use

https://github.com/gramps-project/gramps/blob/e361c6dd4942366fc23f4a3c47fa020e482660df/gramps/gui/widgets/monitoredwidgets.py#L619

Hope this helps!

Steve.

On 13/05/2020 05:51, Dennis Bareis wrote:
Hi,

I have tried code similar to the following (with and without the modifier).

d = Date()
d.set(text='First of Jan',  modifier=Date.MOD_TEXTONLY)

If I display the str(d) I get "0000-00-00"

Maybe "set" is not the right way but there must be a way to correctly set up a Date() object from a user-defined text string (as long as the format is valid).

---
Thanks
Dennis


Mailtrack Sender notified by
Mailtrack 13/05/20, 02:49:19 pm



_______________________________________________
Gramps-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-devel


_______________________________________________
Gramps-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-devel