After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 579055 - SOUP_DATE_RFC2822 not handled in soup_date_to_string()
SOUP_DATE_RFC2822 not handled in soup_date_to_string()
Status: RESOLVED FIXED
Product: libsoup
Classification: Core
Component: API
2.26.x
Other Linux
: Normal minor
: ---
Assigned To: libsoup-maint@gnome.bugs
libsoup-maint@gnome.bugs
Depends on:
Blocks:
 
 
Reported: 2009-04-15 14:53 UTC by Enrico Tröger
Modified: 2009-04-18 15:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add RFC2822 format to soup_date_to_string() and use a leading zero for day of month (1.38 KB, patch)
2009-04-15 14:54 UTC, Enrico Tröger
needs-work Details | Review
Version 2 of the patch (2.00 KB, patch)
2009-04-15 16:20 UTC, Enrico Tröger
none Details | Review
Version 3 of the patch (1.95 KB, patch)
2009-04-15 16:57 UTC, Enrico Tröger
none Details | Review

Description Enrico Tröger 2009-04-15 14:53:48 UTC
When passing a SOUP_DATE_RFC2822 SoupDateFormat to soup_date_to_string() it returns NULL. After having a short look at the sources, it seems there is just a case statement for the RFC2822 format missing to generate a proper date string.

Also I think it might be better to use a leading 0 digit for the day of month in the RFC2822 date format. Though I couldn't find a clear statement about this in the RFC, date(1) seems to prefer a leading zero for the first 9 days of a month :).
Comment 1 Enrico Tröger 2009-04-15 14:54:46 UTC
Created attachment 132703 [details] [review]
Add RFC2822 format to soup_date_to_string() and use a leading zero for day of month
Comment 2 Dan Winship 2009-04-15 15:18:57 UTC
(In reply to comment #0)
> When passing a SOUP_DATE_RFC2822 SoupDateFormat to soup_date_to_string() it
> returns NULL. After having a short look at the sources, it seems there is just
> a case statement for the RFC2822 format missing to generate a proper date
> string.

oops. Though apparently I knew this at one point. If you look at tests/date.c, the RFC2822 test is #ifdeffed out. (You should fix that too, and make sure the test passes after that.)

> Also I think it might be better to use a leading 0 digit for the day of month
> in the RFC2822 date format. Though I couldn't find a clear statement about this
> in the RFC, date(1) seems to prefer a leading zero for the first 9 days of a
> month :).

What date(1) does doesn't matter though because it's not generating an RFC 2822 date. The fact that the grammar even allows a single-digit day strongly implies that leading 0s are not desired, and some of the examples elsewhere in the RFC use single-digit dates. Eg:

    Date: Tue, 1 Jul 2003 10:52:37 +0200

So we shouldn't use leading 0s.


Also, I'm pretty sure that SoupDate's offset has the opposite sign from RFC2822's offset, so you need to flip the '-' vs '+' test. (Making sure to still use '+' for the 0000 case though.) You should check that dates with offsets roundtrip between soup_date_new_from_string() and soup_date_to_string() properly.


Just out of curiosity, what are you working on that you need this to work for?
Comment 3 Enrico Tröger 2009-04-15 16:20:53 UTC
Created attachment 132712 [details] [review]
Version 2 of the patch

Ok, thanks for the feedback.

I don't have a strong opinion on the leading zeros in the day of month. When I was referring to date(1), I forgot to mention to use its -R switch to produce RFC2822 dates. Anyway, you are right that in the RFC examples no leading zeroes are used, so I removed that part from the patch.

I changed the code in parse_timezone() a little to parse timezone parts of a date without a separating colon.

And finally I changed the test program to test RFC 2822 dates and I changed the test date to contain a non-UTC timezone. Tests passed though I'm not 100% sure all is working fine now.

Btw, in the first patch there was a nasty bug which produced completely wrong timezone parts if the offset was negative, I fixed this by adding two abs() calls.

About my motivation on this:
I recently wrote a cookie manager for Midori, mainly just to view the cookies the browser uses. And when displaying a cookie, I used soup_date_to_string(cookie->expires, SOUP_DATE_RFC2822) to display the expiration time. Then I wondered why I always get NULL instead of a datetime string :). In the meantime, I'm using soup_date_to_time_t() and strftime() but adding this part to libsoup probably won't hurt.
Comment 4 Enrico Tröger 2009-04-15 16:29:44 UTC
Oh, forgot to mention: sorry if I broke the coding style. I wasn't sure at all about the indentation and stuff.
Comment 5 Enrico Tröger 2009-04-15 16:57:09 UTC
Created attachment 132715 [details] [review]
Version 3 of the patch

Oops, there was an unintended debug output included in the patch.
Comment 6 Dan Winship 2009-04-15 17:14:57 UTC
(In reply to comment #3)
> About my motivation on this:
> I recently wrote a cookie manager for Midori, mainly just to view the cookies
> the browser uses. And when displaying a cookie, I used
> soup_date_to_string(cookie->expires, SOUP_DATE_RFC2822) to display the
> expiration time.

Oh, you don't want to do that. :-) All of the formats soup_date_to_string() supports are non-localized, so you'll get English day and month names regardless of what language the user is using. So using strftime() is actually better. (Maybe there should be a soup_date_strftime()? Hm...)

But the patch is good anyway. I'll look at it more and commit it this weekend or something.
Comment 7 Enrico Tröger 2009-04-15 17:27:05 UTC
(In reply to comment #6)
> (In reply to comment #3)
> > About my motivation on this:
> > I recently wrote a cookie manager for Midori, mainly just to view the cookies
> > the browser uses. And when displaying a cookie, I used
> > soup_date_to_string(cookie->expires, SOUP_DATE_RFC2822) to display the
> > expiration time.
> 
> Oh, you don't want to do that. :-) All of the formats soup_date_to_string()
> supports are non-localized, so you'll get English day and month names

Yup, realised this as well :).


> regardless of what language the user is using. So using strftime() is actually
> better. (Maybe there should be a soup_date_strftime()? Hm...)

That would be nice though not strictly necessary. What I do now is:

expiration_time = soup_date_to_time_t(cookie->expires);
tm = localtime(&expiration_time);
strftime(date_fmt, sizeof(date_fmt), "%c", tm);

That's enough to get it working.


> But the patch is good anyway. I'll look at it more and commit it this weekend
> or something.

Cool.

Comment 8 Dan Winship 2009-04-18 15:47:15 UTC
pushed to git with some additional improvements and regression tests. thanks for the patch. this will eventually end up in 2.26.2