Made HTTP_DATE more flexible and support UTC+0000, GMT+0000 and now also +0000.
Added comments.
This commit is contained in:
@@ -122,8 +122,8 @@ feature {NONE} -- Internal
|
|||||||
feature -- Conversion to string
|
feature -- Conversion to string
|
||||||
|
|
||||||
yyyy_mmm_dd_string: STRING
|
yyyy_mmm_dd_string: STRING
|
||||||
-- String representation YYYY mmm dd
|
-- String representation [YYYY mmm dd]
|
||||||
-- 2012 Dec 25
|
-- ex: 2012 Dec 25
|
||||||
do
|
do
|
||||||
create Result.make (11)
|
create Result.make (11)
|
||||||
append_date_time_to_yyyy_mmm_dd_string (date_time, Result)
|
append_date_time_to_yyyy_mmm_dd_string (date_time, Result)
|
||||||
@@ -131,7 +131,8 @@ feature -- Conversion to string
|
|||||||
|
|
||||||
rfc1123_string: STRING
|
rfc1123_string: STRING
|
||||||
-- String representation following RFC 1123.
|
-- String representation following RFC 1123.
|
||||||
--| Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
|
-- format: [ddd, dd mmm yyyy hh:mi:ss GMT]
|
||||||
|
-- ex: Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
|
||||||
local
|
local
|
||||||
s: like internal_rfc1123_string
|
s: like internal_rfc1123_string
|
||||||
do
|
do
|
||||||
@@ -145,7 +146,8 @@ feature -- Conversion to string
|
|||||||
end
|
end
|
||||||
|
|
||||||
rfc850_string: STRING
|
rfc850_string: STRING
|
||||||
-- String representation following RFC 850
|
-- String representation following RFC 850.
|
||||||
|
-- format: [mmm, dd-mmm-yy hh:mi:ss GMT]
|
||||||
do
|
do
|
||||||
create Result.make (32)
|
create Result.make (32)
|
||||||
append_date_time_to_rfc850_string (date_time, Result)
|
append_date_time_to_rfc850_string (date_time, Result)
|
||||||
@@ -153,6 +155,7 @@ feature -- Conversion to string
|
|||||||
|
|
||||||
ansi_c_string: STRING
|
ansi_c_string: STRING
|
||||||
-- ANSI C's asctime() format
|
-- ANSI C's asctime() format
|
||||||
|
--| Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
|
||||||
do
|
do
|
||||||
create Result.make (32)
|
create Result.make (32)
|
||||||
append_date_time_to_ansi_c_string (date_time, Result)
|
append_date_time_to_ansi_c_string (date_time, Result)
|
||||||
@@ -161,74 +164,34 @@ feature -- Conversion to string
|
|||||||
feature -- Conversion into string
|
feature -- Conversion into string
|
||||||
|
|
||||||
append_to_yyyy_mmm_dd_string (s: STRING_GENERAL)
|
append_to_yyyy_mmm_dd_string (s: STRING_GENERAL)
|
||||||
local
|
-- Append `datetime' as [yyyy mmm dd] format to `s'.
|
||||||
dt: DATE_TIME
|
|
||||||
do
|
do
|
||||||
dt := date_time
|
append_date_time_to_yyyy_mmm_dd_string (date_time, s)
|
||||||
append_integer_to (dt.year, s) -- yyyy
|
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
|
||||||
append_month_mmm_to (dt.month, s) -- mmm
|
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
|
||||||
append_2_digits_integer_to (dt.day, s) -- dd
|
|
||||||
end
|
end
|
||||||
|
|
||||||
append_to_rfc1123_string (s: STRING_GENERAL)
|
append_to_rfc1123_string (s: STRING_GENERAL)
|
||||||
local
|
-- Append `date_time' as [ddd, dd mmm yyyy hh:mi:ss GMT] format to `s'.
|
||||||
dt: DATE_TIME
|
|
||||||
do
|
do
|
||||||
dt := date_time
|
append_date_time_to_rfc1123_string (date_time, s)
|
||||||
append_day_ddd_to (dt.date.day_of_the_week, s) -- ddd
|
|
||||||
s.append_code (44) -- 44 ',' -- ','
|
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
|
||||||
append_2_digits_integer_to (dt.day, s) -- dd
|
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
|
||||||
append_month_mmm_to (dt.month, s) -- mmm
|
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
|
||||||
append_integer_to (dt.year, s) -- YYYY
|
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
|
||||||
append_2_digits_time_to (dt.time, s) -- hh:mi:ss
|
|
||||||
s.append (" GMT") -- SPace + GMT
|
|
||||||
end
|
end
|
||||||
|
|
||||||
append_rfc850_string (s: STRING_GENERAL)
|
append_rfc850_string (s: STRING_GENERAL)
|
||||||
local
|
-- Append `date_time' as [mmm, dd-mmm-yy hh:mi:ss GMT] format to `s'.
|
||||||
dt: DATE_TIME
|
|
||||||
do
|
do
|
||||||
dt := date_time
|
append_date_time_to_rfc850_string (date_time, s)
|
||||||
append_day_name_to (dt.date.day_of_the_week, s) -- mmm
|
|
||||||
s.append_code (44) -- 44 ',' -- ','
|
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
|
||||||
append_2_digits_integer_to (dt.day, s) -- dd
|
|
||||||
s.append_code (45) -- 45 '-' -- '-'
|
|
||||||
append_month_mmm_to (dt.month, s) -- mmm
|
|
||||||
s.append_code (45) -- 45 '-' -- '-'
|
|
||||||
append_integer_to (dt.year \\ 100, s) -- yy
|
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
|
||||||
append_2_digits_time_to (dt.time, s) -- hh:mi:ss
|
|
||||||
s.append (" GMT") -- SPace + GMT
|
|
||||||
end
|
end
|
||||||
|
|
||||||
append_to_ansi_c_string (s: STRING_GENERAL)
|
append_to_ansi_c_string (s: STRING_GENERAL)
|
||||||
|
-- Append `date_time' as ANSI C's asctime format to `s'.
|
||||||
--| Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
|
--| Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
|
||||||
local
|
|
||||||
dt: DATE_TIME
|
|
||||||
do
|
do
|
||||||
dt := date_time
|
append_date_time_to_ansi_c_string (date_time, s)
|
||||||
append_day_ddd_to (dt.date.day_of_the_week, s) -- ddd
|
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
|
||||||
append_month_mmm_to (dt.month, s) -- mmm
|
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
|
||||||
append_integer_to (dt.day, s) -- d
|
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
|
||||||
append_2_digits_time_to (dt.time, s) -- hh:mi:ss
|
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
|
||||||
append_integer_to (dt.year, s) -- yyyy
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Conversion into string
|
feature -- Conversion into string
|
||||||
|
|
||||||
append_date_time_to_yyyy_mmm_dd_string (dt: DATE_TIME; s: STRING_GENERAL)
|
append_date_time_to_yyyy_mmm_dd_string (dt: DATE_TIME; s: STRING_GENERAL)
|
||||||
|
-- Append `dt' as [yyyy mmm dd] format to `s'.
|
||||||
do
|
do
|
||||||
append_integer_to (dt.year, s) -- yyyy
|
append_integer_to (dt.year, s) -- yyyy
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
s.append_code (32) -- 32 ' ' -- SPace
|
||||||
@@ -238,6 +201,7 @@ feature -- Conversion into string
|
|||||||
end
|
end
|
||||||
|
|
||||||
append_date_time_to_rfc1123_string (dt: DATE_TIME; s: STRING_GENERAL)
|
append_date_time_to_rfc1123_string (dt: DATE_TIME; s: STRING_GENERAL)
|
||||||
|
-- Append `dt' as [ddd, dd mmm yyyy hh:mi:ss GMT] format to `s'.
|
||||||
do
|
do
|
||||||
append_day_ddd_to (dt.date.day_of_the_week, s) -- ddd
|
append_day_ddd_to (dt.date.day_of_the_week, s) -- ddd
|
||||||
s.append_code (44) -- 44 ',' -- ','
|
s.append_code (44) -- 44 ',' -- ','
|
||||||
@@ -253,6 +217,7 @@ feature -- Conversion into string
|
|||||||
end
|
end
|
||||||
|
|
||||||
append_date_time_to_rfc850_string (dt: DATE_TIME; s: STRING_GENERAL)
|
append_date_time_to_rfc850_string (dt: DATE_TIME; s: STRING_GENERAL)
|
||||||
|
-- Append `dt' as [mmm, dd-mmm-yy hh:mi:ss GMT] format to `s'.
|
||||||
do
|
do
|
||||||
append_day_name_to (dt.date.day_of_the_week, s) -- mmm
|
append_day_name_to (dt.date.day_of_the_week, s) -- mmm
|
||||||
s.append_code (44) -- 44 ',' -- ','
|
s.append_code (44) -- 44 ',' -- ','
|
||||||
@@ -268,7 +233,8 @@ feature -- Conversion into string
|
|||||||
end
|
end
|
||||||
|
|
||||||
append_date_time_to_ansi_c_string (dt: DATE_TIME; s: STRING_GENERAL)
|
append_date_time_to_ansi_c_string (dt: DATE_TIME; s: STRING_GENERAL)
|
||||||
--| Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
|
-- Append `dt' as ANSI C's asctime format to `s'.
|
||||||
|
-- Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
|
||||||
do
|
do
|
||||||
append_day_ddd_to (dt.date.day_of_the_week, s) -- ddd
|
append_day_ddd_to (dt.date.day_of_the_week, s) -- ddd
|
||||||
s.append_code (32) -- 32 ' ' -- SPace
|
s.append_code (32) -- 32 ' ' -- SPace
|
||||||
@@ -294,7 +260,7 @@ feature -- Status report
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature -- Helper routines.
|
||||||
|
|
||||||
append_2_digits_integer_to (i: INTEGER; s: STRING_GENERAL)
|
append_2_digits_integer_to (i: INTEGER; s: STRING_GENERAL)
|
||||||
require
|
require
|
||||||
@@ -599,7 +565,11 @@ feature {NONE} -- Implementation
|
|||||||
t.extend (s[i].as_upper)
|
t.extend (s[i].as_upper)
|
||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
if t.same_string ("GMT") or t.same_string ("UTC") then
|
if
|
||||||
|
t.same_string ("GMT") -- for instance: GMT+0002
|
||||||
|
or t.same_string ("UTC") -- for instance: UTC+0002
|
||||||
|
or t.is_empty -- for instance: +0002
|
||||||
|
then
|
||||||
from until i > n or else not s[i].is_space loop i := i + 1 end
|
from until i > n or else not s[i].is_space loop i := i + 1 end
|
||||||
if i <= n then
|
if i <= n then
|
||||||
t.wipe_out
|
t.wipe_out
|
||||||
|
|||||||
Reference in New Issue
Block a user