Newbee
Newbee

Reputation: 1397

What is valid RFC1123 date format

I am working on a service which returns expires header. The service will be working across different timezone. So we need a way to return other timezones than GMT.

I know that the http header have to follow RFC1123 standard date format. So the service returns date like below -

Fri, 01 Mar 2019 15:00:00 GMT

What I need is return the date in below format.

Fri, 01 Mar 2019 15:00:00 +0530

Is this a valid date for RFC1123 date format?

Upvotes: 5

Views: 29239

Answers (2)

tl;dr:

Fri, 01 Mar 2019 15:00:00 +0530 is RFC 1123-compliant but not RFC 2616 (HTTP 1.1)-compliant.


RFC 1123 supersedes RFC 882, which originally defined the standard internet date-time formats, and according to the relevant section of the latter:

date-time   =  [ day "," ] date time        ; dd mm yy
                                            ;  hh:mm:ss zzz

day         =  "Mon"  / "Tue" /  "Wed"  / "Thu"
            /  "Fri"  / "Sat" /  "Sun"

date        =  1*2DIGIT month 2DIGIT        ; day month year
                                            ;  e.g. 20 Jun 82

month       =  "Jan"  /  "Feb" /  "Mar"  /  "Apr"
            /  "May"  /  "Jun" /  "Jul"  /  "Aug"
            /  "Sep"  /  "Oct" /  "Nov"  /  "Dec"

time        =  hour zone                    ; ANSI and Military

hour        =  2DIGIT ":" 2DIGIT [":" 2DIGIT]
                                            ; 00:00:00 - 23:59:59

zone        =  "UT"  / "GMT"                ; Universal Time
                                            ; North American : UT
            /  "EST" / "EDT"                ;  Eastern:  - 5/ - 4
            /  "CST" / "CDT"                ;  Central:  - 6/ - 5
            /  "MST" / "MDT"                ;  Mountain: - 7/ - 6
            /  "PST" / "PDT"                ;  Pacific:  - 8/ - 7
            /  1ALPHA                       ; Military: Z = UT;
                                            ;  A:-1; (J not used)
                                            ;  M:-12; N:+1; Y:+12
            / ( ("+" / "-") 4DIGIT )        ; Local differential
                                            ;  hours+min. (HHMM)

The only change that RFC 1123 made to the above is to update date to preferably use a 4-digit year, such that the full RFC 1123 specification is effectively:

date-time   =  [ day "," ] date time        ; dd mm yy
                                            ;  hh:mm:ss zzz

day         =  "Mon"  / "Tue" /  "Wed"  / "Thu"
            /  "Fri"  / "Sat" /  "Sun"

date        =  1*2DIGIT month 2*4DIGIT      ; day month year
                                            ;  e.g. 20 Jun 1982
                                            ; changed from RFC 822

month       =  "Jan"  /  "Feb" /  "Mar"  /  "Apr"
            /  "May"  /  "Jun" /  "Jul"  /  "Aug"
            /  "Sep"  /  "Oct" /  "Nov"  /  "Dec"

time        =  hour zone                    ; ANSI and Military

hour        =  2DIGIT ":" 2DIGIT [":" 2DIGIT]
                                            ; 00:00:00 - 23:59:59

zone        =  "UT"  / "GMT"                ; Universal Time
                                            ; North American : UT
            /  "EST" / "EDT"                ;  Eastern:  - 5/ - 4
            /  "CST" / "CDT"                ;  Central:  - 6/ - 5
            /  "MST" / "MDT"                ;  Mountain: - 7/ - 6
            /  "PST" / "PDT"                ;  Pacific:  - 8/ - 7
            /  1ALPHA                       ; Military: Z = UT;
                                            ;  A:-1; (J not used)
                                            ;  M:-12; N:+1; Y:+12
            / ( ("+" / "-") 4DIGIT )        ; Local differential
                                            ;  hours+min. (HHMM)

So if the software reading your header requires it to be in RFC 1123 format, then yes, Fri, 01 Mar 2019 15:00:00 +0530 is a completely valid date-time. However, it is not a valid HTTP 1.1 date-time value!

This is because RFCs 822 and 1123 are concerned primarily with SMTP, not HTTP. It is RFC 2616 that defines allowed date-time formats for HTTP specifically, and it is far more strict in what is permitted:

HTTP applications have historically allowed three different formats
for the representation of date/time stamps:

  Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
  Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
  Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format

The first format is preferred as an Internet standard and represents
a fixed-length subset of that defined by RFC 1123 [8] (an update to
RFC 822 [9]). The second format is in common use, but is based on the
obsolete RFC 850 [12] date format and lacks a four-digit year.
HTTP/1.1 clients and servers that parse the date value MUST accept
all three formats (for compatibility with HTTP/1.0), though they MUST
only generate the RFC 1123 format for representing HTTP-date values
in header fields. See section 19.3 for further information.

RFC 2616 is obsoleted by RFC 7231, which makes the above more explicit:

An example of the preferred format is

  Sun, 06 Nov 1994 08:49:37 GMT    ; IMF-fixdate

Examples of the two obsolete formats are

  Sunday, 06-Nov-94 08:49:37 GMT   ; obsolete RFC 850 format
  Sun Nov  6 08:49:37 1994         ; ANSI C's asctime() format

...

An HTTP-date value represents time as an instance of Coordinated
Universal Time (UTC).

In short, if you are writing a strictly HTTP 1.1-compliant application, you are not permitted to encode timezone information into a date-time type value; you must convert that value to an absolute (UTC) date-time, and transmit the latter.

Therefore, if you intend for your application to be both RFC 1123-compliant and HTTP 1.1-compliant, then the value Fri, 01 Mar 2019 15:00:00 +0530 is invalid. In contrast, the value Fri, 01 Mar 2019 09:30:00 GMT (which represents the same point in time), is valid for both specifications.

Upvotes: 1

cassiomolin
cassiomolin

Reputation: 130887

I guess you are using the old and obsolete RFC 2616 as reference. Please bear in mind that this document is no longer relevant nowadays and has been replaced with the following documents:


According to RFC 7231, HTTP dates must be expressed in GMT. So expressing dates with offsets from UTC is invalid.


See how the Expires header is defined in RFC 7234:

5.3. Expires

The Expires header field gives the date/time after which the response is considered stale. [...]

The Expires value is an HTTP-date timestamp, as defined in Section 7.1.1.1 of RFC 7231.

 Expires = HTTP-date

For example

Expires: Thu, 01 Dec 1994 16:00:00 GMT

Now see the following quote from RFC 7231:

7.1.1.1. Date/Time Formats

Prior to 1995, there were three different formats commonly used by servers to communicate timestamps. For compatibility with old implementations, all three are defined here. The preferred format is a fixed-length and single-zone subset of the date and time specification used by the Internet Message Format [RFC5322].

HTTP-date    = IMF-fixdate / obs-date

An example of the preferred format is

Sun, 06 Nov 1994 08:49:37 GMT    ; IMF-fixdate

Examples of the two obsolete formats are

Sunday, 06-Nov-94 08:49:37 GMT   ; obsolete RFC 850 format
Sun Nov  6 08:49:37 1994         ; ANSI C's asctime() format

A recipient that parses a timestamp value in an HTTP header field MUST accept all three HTTP-date formats. When a sender generates a header field that contains one or more timestamps defined as HTTP-date, the sender MUST generate those timestamps in the IMF-fixdate format.

An HTTP-date value represents time as an instance of Coordinated Universal Time (UTC). The first two formats indicate UTC by the three-letter abbreviation for Greenwich Mean Time, GMT, a predecessor of the UTC name; values in the asctime format are assumed to be in UTC. [...]

Upvotes: 12

Related Questions