On Tue, 18 Apr 2017, Benoît Minisini wrote:
> Le 18/04/2017 à 19:52, Benoît Minisini a écrit :
> > Le 18/04/2017 à 19:44, Tobias Boege a écrit :
> >> On Sun, 16 Apr 2017, Benoît Minisini wrote:
> >>> Le 02/04/2017 à 18:07, Tobias Boege a écrit :
> >>>>
> >>>>   * The date conversion routines ignore timezones completely, because
> >>>>     I have no clue about working with timezones in Gambas.
> >>>>
> >>>
> >>> Hi, Tobias.
> >>>
> >>> I have added in revision #8122 two functions to the gb.util component:
> >>>
> >>> Date.ToRFC822(), to convert a Gambas date/time value to its RFC822
> >>> string representation, with the timezone.
> >>>
> >>> Date.FromRFC822(), to do the contrary.
> >>>
> >>> Tell me if you can use them, and if you need me to add the same
> >>> functions for RFC3339 date format used by Atom.
> >>>
> >>
> >> Thanks for these. Reading the code (not testing it yet), I noticed four
> >> things:
> >>
> >>   * The weekday and second parts in the format are optional in the RFC
> >>     but mandatory in your parser.
> >>
> >>   * The year is a 2-digit number in the RFC. The RSS spec says it prefers
> >>     4 digits. My current parser in gb.web.feed supports both, but treats
> >>     2-digit years XY as 19XY (which I think is the most sensible
> >>     interpretation with respect to the RFC but sadly excludes publication
> >>     dates for news items near Christ's birth).
> >>
> >>   * There is no consistency check in the parser if, in case a weekday is
> >>     given, it matches the weekday of the date, like
> >>
> >>       Fri, 18 Apr 2017 12:00:00 GMT
> >>
> >>     would be invalid by the RFC ("5.2 SEMANTICS"), because the 18 Apr
> >> 2017
> >>     is a Tuesday.
> >>
> >>   * At one point you use Format$(..., "hh:nn:ss") which I think may be
> >>     dangerous, because Format$() (as per docs) replaces ":" by the
> >> locale-
> >>     specific time separator. I don't know if there are locales where this
> >>     is different from ":", but the RFC requires it to be ":" exactly.
> >>
> >> My parser does these four things. If you want to add them, the
> >> gb.web.feed
> >> code is sufficiently commented in the relevant places.
> >
> > OK, I will look at it.
> >
> 
> I have updated the gb.util components with your fixes. Now I think you 
> can use it directly in gb.web.feed.
> 

I think there is something wrong with at least one of these functions.
In FromRFC822() you do towards the end:

  (1)  dDate -= Frac(Date(Now))
  (2)  dDate += GetRFC822Zone(aDate[6])

What is (1) supposed to do? Isn't Frac(Date(Now)) the current time?

Regarding (2), I think I could (after an hour) wrap my head around when
to add and when to subtract the timezone offsets in a conversion and
FromRFC822() should *subtract* the timezone offset from the date, like

  18:00:00 +0200

is the same point in time as

  16:00:00 +0000

(isn't it?)

And in ToRFC822() you do something with System.TimeZone. Isn't a Date value
assumed to be relative to UTC, or +0000? So why bring the system's timezone
into the equation when a target timezone is given by the TimeZone argument?
Or is the Date input supposed to be in the local timezone? Then ToRFC822()
and FromRFC822() wouldn't be inverse to each other...

For example, I'm in +0200 currently (I think) and converting 6pm as a time
in GMT to GMT again results in 2pm:

  Print Date.ToRFC822(Date.FromRFC822("27 Apr 2017 18:00:00 GMT"), "GMT")
  Thu, 27 Apr 2017 14:0:0 GMT

You can also see that ToRFC822() misses Format(..., "00") calls in the time
components.

And could you add an Optional ByRef TimeZone As String argument to
FromRFC822() and set it to aDate[6] just before the function returns?
The rationale is: in gb.web.feed I still want to have an RssDate class
with a Date and a TimeZone member. When reading a date, I want to initialise
the TimeZone member with the timezone given in the RFC822 string, so that
reading an RSS document into an Rss object and then serialising that Rss
object immediately afterwards doesn't change all the timezone strings in
the document.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to