Re: [gnome-db] check gdatime and gdatimestamp validity

Vivien Malerba <[email protected]>
Newsgroups gmane.comp.gnome.db
Message-ID <[email protected]>
On 10 July 2010 13:01, Andrea Zagli <[email protected]> wrote:
> i wrote these two functions to validate gdatime and gdatimestamp
>
> /**
>  * gda_time_valid
>  * @time: a #GdaTime value to check if it is valid
>  *
>  * Returns: #TRUE if #GdaTime is valid; FALSE otherwise.
>  */
> gboolean
> gda_time_valid (const GdaTime *time)
> {
>        g_return_val_if_fail (time != NULL, FALSE);
>
>        if (time->hour < 0 || time->hour > 24
>            || time->minute < 0 || time->minute > 59
>            || time->second < 0 || time->second > 59)
>                return FALSE;
>        /* TODO i don't undestand how timestamp->timezone work */
>        /* TODO i don't know how timestamp->fraction work */
>
>        return TRUE;
> }
>
> /**
>  * gda_timestamp_valid
>  * @timestamp: a #GdaTimestamp value to check if it is valid
>  *
>  * Returns: #TRUE if #GdaTimestamp is valid; FALSE otherwise.
>  */
> gboolean
> gda_timestamp_valid (const GdaTimestamp *timestamp)
> {
>        g_return_val_if_fail (timestamp != NULL, FALSE);
>
>        GDate *gdate;
>
>        /* check the date part */
>        gdate = g_date_new_dmy ((GDateDay)timestamp->day,
> (GDateMonth)timestamp->month, (GDateYear)timestamp->year);
>        if (gdate == NULL)
>                return FALSE;
>
>        /* check the time part */
>        if (timestamp->hour < 0 || timestamp->hour > 24
>            || timestamp->minute < 0 || timestamp->minute > 59
>            || timestamp->second < 0 || timestamp->second > 59)
>                return FALSE;
>        /* TODO i don't undestand how timestamp->timezone work */
>        /* TODO i don't know how timestamp->fraction work */
>
>        return TRUE;
> }

Added to git/master, see
http://git.gnome.org/browse/libgda/commit/?id=8ccc54aa2dc0e7e9ed09790ddaf12727f6770644

>
> if you think that it can be useful inside libgda, fell free to use them (i
> think that libgda functions  operating on gdatime and gdatime (ex.
> gda_value_get_timestamp) must before validate the value)
>

I prefer to let the user decide when to validate his own data, but I
think they are usefull functions.

Thanks a lot,

Vivien
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.