gnumed-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnumed-devel] date of birth - how to handle


From: Karsten Hilbert
Subject: Re: [Gnumed-devel] date of birth - how to handle
Date: Mon, 5 Jul 2010 13:26:27 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

On Mon, Jul 05, 2010 at 01:07:02PM +0200, Hilbert, Sebastian wrote:

> I am in the process of writing the dob of a patient to a XML file.
> gmCurrentPatient returns a datetime object. Different from a database backend 
> I cannot store the object in a XML file. I therefore convert it with 
> 
> pat['dob'].strftime("%x"). This works and puts out a locale formated string 
> representation. I wonder if there is a way to determine the format datetime 
> has used in this very case (DDMMYYYY or MMDDYY) ?  

Have a look at the Python docs for the locale module.
Excerpt:

    locale.D_T_FMT¶        Get a string that can be used as a format string for 
strftime() to represent time and date in a locale-specific way.    
    locale.D_FMT¶        Get a string that can be used as a format string for 
strftime() to represent a date in a locale-specific way.    
    locale.T_FMT¶        Get a string that can be used as a format string for 
strftime() to represent a time in a locale-specific way.    
    locale.T_FMT_AMPM¶        Get a format string for strftime() to represent 
time in the am/pm format.

I would NOT suggest to rely on that, though. It isn't
available cross-platform either.

Decide on a format and use that. See the ISO8601 docs.

> When reading in the XML files I need to convert the string representation 
> into 
> a date (e.g. for examination date).
> 
> Which is the best format for storage and reconverting it into a datetime 
> object ?

Some form of ISO8601.

> I would like to store and read the format used from the XML tag's property. 
> How do I get the format used ? I would like to avoid hardcoding the format.

You are better off doing so.

Karsten
-- 
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346



reply via email to

[Prev in Thread] Current Thread [Next in Thread]