added jj_temporal source code

This commit is contained in:
2024-06-19 15:01:51 +02:00
parent d551f35d2f
commit 4df573d730
93 changed files with 13000 additions and 1 deletions

View File

@@ -0,0 +1,192 @@
note
description: "[
Utility class for converting {HMS_DURATION}'s to and from
strings based on a selected `format'. While the string given
by feature `as_string' is set based on the format, the parsing
of a string to a duration in feature `to_hms_duration' is more
relaxed.
]"
date: "18 Feb 03"
author: "Jimmy J. Johnson"
copyright: "Copyright 2009, Jimmy J. Johnson"
license: "Eiffel Forum License v2 (see forum.txt)"
URL: "$URL:$"
date: "$Date: 2009-06-25 21:37:23 -0400 (Thu, 25 Jun 2009) $"
revision: "$Revision: 7 $"
class
HMS_DURATION_FORMATTER
inherit
ANY
redefine
default_create
end
create
default_create
feature {NONE} -- Initialization
default_create
do
set_separator (", ")
set_hour_minute_second
end
feature -- Access
separator: STRING
feature -- Element change
set_separator (a_string: STRING)
require
string_exists: a_string /= Void
do
separator := a_string
end
set_hour_minute_second
-- Set format to day-month-year.
do
format := hms
end
set_second_minute_hour
do
format := smh
end
set_hour_minute
do
format := hm
end
set_minute_hour
do
format := mh
end
feature -- Access
hour_string (a_duration: HMS_DURATION): STRING
do
create Result.make(8)
Result.append_integer (a_duration.hours)
Result.append (" hour")
if a_duration.hours /= 1 and a_duration.hours /= -1 then
Result.append ("s")
end
end
minute_string (a_duration: HMS_DURATION): STRING
do
create Result.make (8)
Result.append_integer (a_duration.minutes)
Result.append (" minute")
if a_duration.minutes /= 1 and a_duration.minutes /= -1 then
Result.append ("s")
end
end
second_string (a_duration: HMS_DURATION): STRING
do
create Result.make (8)
Result.append_integer (a_duration.seconds)
Result.append (" second")
if a_duration.seconds /= 1 and a_duration.seconds /= -1 then
Result.append ("s")
end
end
to_string (a_duration: HMS_DURATION): STRING
-- the whole duration as a string
do
create Result.make (20)
Result.append (hour_string(a_duration))
Result.append (separator)
Result.append (minute_string(a_duration))
Result.append (separator)
Result.append (second_string(a_duration))
end
string_to_duration (a_string: STRING): HMS_DURATION
-- Parse the string based on the current formatting.
require
valid_date_string: is_valid_duration_string (a_string)
do
check
fix_me: False then
end
end
feature -- Query
is_valid_duration_string (a_string: STRING): BOOLEAN
require
string_exists: a_string /= Void
do
-- parse the string
Result := True
-- !!! temporary
end
is_index_in_hour_string (a_date: HMS_DURATION; a_index: INTEGER): BOOLEAN
require
date_exists: a_date /= Void
-- index_large_enough: a_index >= 1
local
s, ds: STRING
i: INTEGER
do
s := to_string (a_date)
ds := hour_string (a_date)
i := s.substring_index (ds, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + ds.count-1
end
end
is_index_in_minute_string (a_date: HMS_DURATION; a_index: INTEGER): BOOLEAN
local
s, ms: STRING
i: INTEGER
do
s := to_string (a_date)
ms := minute_string (a_date)
i := s.substring_index (ms, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + ms.count-1
end
end
is_index_in_second_string (a_date: HMS_DURATION; a_index: INTEGER): BOOLEAN
local
s, ys: STRING
i: INTEGER
do
s := to_string (a_date)
ys := second_string (a_date)
i := s.substring_index (ys, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + ys.count-1
end
end
feature {NONE} -- Implementation
format: INTEGER
hms, smh, -- hours-minutes-seconds, etc
hm, mh : INTEGER = unique -- hours-minutes only
hms_parse (a_string: STRING)
do
end
end -- class HMS_DURATION_FORMATTER

View File

@@ -0,0 +1,245 @@
note
description: "[
Utility class for converting {HMS_TIME}'s to and from
strings based on a selected `format'. While the string given
by feature `to_string' is set based on the format, the parsing
of a string to a duration in feature `to_hms_time' is more
relaxed.
]"
date: "18 Feb 03"
author: "Jimmy J. Johnson"
copyright: "Copyright 2009, Jimmy J. Johnson"
license: "Eiffel Forum License v2 (see forum.txt)"
URL: "$URL:$"
date: "$Date: 2009-06-25 21:37:23 -0400 (Thu, 25 Jun 2009) $"
revision: "$Revision: 7 $"
class
HMS_TIME_FORMATTER
inherit
ANY
redefine
default_create
end
create
default_create
feature -- Initialization
default_create
do
set_separator (":")
hide_seconds
set_12_hour
end
feature -- Element change
set_separator (a_string: STRING)
require
separator_exists: a_string /= Void
do
separator := a_string
end
set_12_hour
do
is_12_hour := True
end
set_24_hour
do
is_12_hour := False
end
show_seconds
do
is_seconds_shown := True
end
hide_seconds
do
is_seconds_shown := False
end
feature -- Access
separator: STRING
hour_string (a_time: like time_anchor): STRING
require
time_exists: a_time /= Void
local
h: INTEGER
do
h := a_time.hour
if is_12_hour and then h >= 12 then
h := h - 12
end
if is_12_hour and then h = 0 then
h := 12
end
create Result.make(2)
if h < 10 then
Result.append ("0")
end
Result.append_integer (h)
end
minute_string (a_time: like time_anchor): STRING
require
time_exists: a_time /= Void
do
create Result.make(2)
if a_time.minute < 10 then
Result.append ("0")
end
Result.append_integer (a_time.minute)
end
second_string (a_time: like time_anchor): STRING
require
time_exists: a_time /= Void
do
create Result.make(2)
if a_time.second < 10 then
Result.append ("0")
end
Result.append_integer (a_time.second)
end
am_pm_string (a_time: like time_anchor): STRING
require
time_exists: a_time /= Void
do
create Result.make (3)
if a_time.hour >= 12 then
Result.append (" PM")
else
Result.append (" AM")
end
end
to_string (a_time: like time_anchor): STRING
-- the whole {HMS_TIME} as a string
require
time_exists: a_time /= Void
do
create Result.make (20)
Result.append (hour_string (a_time))
Result.append (separator)
Result.append (minute_string (a_time))
if is_seconds_shown then
Result.append (separator)
Result.append (second_string (a_time))
end
if is_12_hour then
Result.append (am_pm_string (a_time))
end
end
feature -- Status report
is_12_hour: BOOLEAN
is_seconds_shown: BOOLEAN
feature -- Query
is_valid_time_string (a_time: STRING): BOOLEAN
require
string_exists: a_time /= Void
do
-- parse the string
end
is_index_in_hour_string (a_time: like time_anchor; a_index: INTEGER): BOOLEAN
require
time_exists: a_time /= Void
-- index_large_enough: a_index >= 1
local
s, hs: STRING
i: INTEGER
do
s := to_string (a_time)
hs := hour_string (a_time)
i := s.substring_index (hs, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + hs.count-1
end
end
is_index_in_minute_string (a_time: like time_anchor; a_index: INTEGER): BOOLEAN
require
time_exists: a_time /= Void
-- index_large_enough: a_index >= 1
local
s, ms: STRING
i: INTEGER
do
s := to_string (a_time)
ms := minute_string (a_time)
i := s.substring_index (ms, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + ms.count-1
end
end
is_index_in_second_string (a_time: like time_anchor; a_index: INTEGER): BOOLEAN
require
time_exists: a_time /= Void
-- index_large_enough: a_index >= 1
local
s, ss: STRING
i: INTEGER
do
s := to_string (a_time)
ss := hour_string (a_time)
i := s.substring_index (ss, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + ss.count-1
end
end
is_index_in_am_pm_string (a_time: like time_anchor; a_index: INTEGER): BOOLEAN
require
time_exists: a_time /= Void
-- index_large_enough: a_index >= 1
local
s, ss: STRING
i: INTEGER
do
s := to_string (a_time)
ss := am_pm_string (a_time)
i := s.substring_index (ss, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + ss.count-1
end
end
feature {NONE} -- Anchors (for covariant redefinitions)
time_anchor: HMS_TIME
-- Not to be called; just used to anchor types.
require
not_callable: False
do
check
do_not_call: False then
-- Because gives no info; simply used as anchor.
end
end
feature {NONE} -- Implementation
hms_parse (a_string: STRING)
do
end
end

View File

@@ -0,0 +1,192 @@
note
description: "[
Utility class for converting {YMD_DURATION}'s to and from
strings based on a selected `format'. While the string given
by feature `as_string' is set based on the format, the parsing
of a string to a duration in feature `to_ymd_duration' is more
relaxed.
]"
author: "Jimmy J. Johnson"
copyright: "Copyright 2009, Jimmy J. Johnson"
license: "Eiffel Forum License v2 (see forum.txt)"
URL: "$URL:$"
date: "$Date: 2009-06-25 21:37:23 -0400 (Thu, 25 Jun 2009) $"
revision: "$Revision: 7 $"
class
YMD_DURATION_FORMATTER
inherit
ANY
redefine
default_create
end
create
default_create
feature {NONE} -- Initialization
default_create
do
set_separator (", ")
set_year_month_day
end
feature -- Access
separator: STRING
feature -- Element change
set_separator (a_string: STRING)
require
string_exists: a_string /= Void
do
separator := a_string
end
set_day_month_year
-- Set format to day-month-year.
do
format := dmy
end
set_year_month_day
do
format := ymd
end
set_day_month
do
format := dm
end
set_month_year
do
format := my
end
feature -- Access
year_string (a_duration: YMD_DURATION): STRING
do
create Result.make(8)
Result.append_integer (a_duration.years)
Result.append (" year")
if a_duration.years /= 1 and a_duration.years /= -1 then
Result.append ("s")
end
end
month_string (a_duration: YMD_DURATION): STRING
do
create Result.make (8)
Result.append_integer (a_duration.months)
Result.append (" month")
if a_duration.months /= 1 and a_duration.months /= -1 then
Result.append ("s")
end
end
day_string (a_duration: YMD_DURATION): STRING
do
create Result.make (8)
Result.append_integer (a_duration.days)
Result.append (" day")
if a_duration.days /= 1 and a_duration.days /= -1 then
Result.append ("s")
end
end
to_string (a_duration: YMD_DURATION): STRING
-- the whole duration as a string
do
create Result.make (20)
Result.append (day_string(a_duration))
Result.append (separator)
Result.append (month_string(a_duration))
Result.append (separator)
Result.append (year_string(a_duration))
end
string_to_duration (a_string: STRING): YMD_DURATION
-- Parse the string based on the current formatting.
require
valid_date_string: is_valid_date_string (a_string)
do
check
fix_me: False then
end
end
feature -- Query
is_valid_date_string (a_string: STRING): BOOLEAN
require
string_exists: a_string /= Void
do
-- parse the string
Result := True
-- !!! temporary
end
is_index_in_day_string (a_date: YMD_DURATION; a_index: INTEGER): BOOLEAN
require
date_exists: a_date /= Void
-- index_large_enough: a_index >= 1
local
s, ds: STRING
i: INTEGER
do
s := to_string (a_date)
ds := day_string (a_date)
i := s.substring_index (ds, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + ds.count-1
end
end
is_index_in_month_string (a_date: YMD_DURATION; a_index: INTEGER): BOOLEAN
local
s, ms: STRING
i: INTEGER
do
s := to_string (a_date)
ms := month_string (a_date)
i := s.substring_index (ms, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + ms.count-1
end
end
is_index_in_year_string (a_date: YMD_DURATION; a_index: INTEGER): BOOLEAN
local
s, ys: STRING
i: INTEGER
do
s := to_string (a_date)
ys := year_string (a_date)
i := s.substring_index (ys, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + ys.count-1
end
end
feature {NONE} -- Implementation
format: INTEGER
dmy, ymd, -- day-month-year, etc
dm, my : INTEGER = unique -- day-month or month-year only
dmy_parse (a_string: STRING)
do
end
end -- class YMD_DURATION_FORMATTER

View File

@@ -0,0 +1,133 @@
note
description: "[
Constants describing how {YMD_TIME}'s (dates) should appear.
]"
author: "Jimmy J. Johnson"
copyright: "Copyright 2009, Jimmy J. Johnson"
license: "Eiffel Forum License v2 (see forum.txt)"
URL: "$URL:$"
date: "$Date: 2009-06-25 21:37:23 -0400 (Thu, 25 Jun 2009) $"
revision: "$Revision: 7 $"
class
YMD_TIME_FORMAT_CONSTANTS
feature -- Assess
Day_month_year: INTEGER = 0
-- (e.g. "31 January 2004" or "31/01/04")
Year_month_day: INTEGER = 1
-- (e.g. "2004 January 31" or "04/01/31")
Month_day_year: INTEGER = 2
-- (e.g. "January 31, 2004" or "01/31/04")
Day_month: INTEGER = 3
-- (e.g. "31 January" or "31/01")
Month_year: INTEGER = 4
-- (e.g. "January 2004" or "01/04")
days_text: LINKED_LIST [STRING]
once
create Result.make
Result.extend ("SUN")
Result.extend ("MON")
Result.extend ("TUE")
Result.extend ("WED")
Result.extend ("THU")
Result.extend ("FRI")
Result.extend ("SAT")
Result.compare_objects
end
months_text: LINKED_LIST [STRING]
once
create Result.make
Result.extend ("JAN")
Result.extend ("FEB")
Result.extend ("MAR")
Result.extend ("APR")
Result.extend ("MAY")
Result.extend ("JUN")
Result.extend ("JUL")
Result.extend ("AUG")
Result.extend ("SEP")
Result.extend ("OCT")
Result.extend ("NOV")
Result.extend ("DEC")
Result.compare_objects
end
long_days_text: LINKED_LIST [STRING]
once
create Result.make
Result.extend ("SUNDAY")
Result.extend ("MONDAY")
Result.extend ("TUESDAY")
Result.extend ("WEDNESDAY")
Result.extend ("THURSDAY")
Result.extend ("FRIDAY")
Result.extend ("SATURDAY")
Result.compare_objects
end
long_months_text: LINKED_LIST [STRING]
--
once
create Result.make
Result.extend ("JANUARY")
Result.extend ("FEBRUARY")
Result.extend ("MARCH")
Result.extend ("APRIL")
Result.extend ("MAY")
Result.extend ("JUNE")
Result.extend ("JULY")
Result.extend ("AUGUST")
Result.extend ("SEPTEMBER")
Result.extend ("OCTOBER")
Result.extend ("NOVEMBER")
Result.extend ("DECEMBER")
Result.compare_objects
end
feature -- Querry
is_valid_format (a_integer: INTEGER): BOOLEAN
-- Does `a_integer' represent a valid date format?
do
Result := a_integer = Day_month_year or else
a_integer = Year_month_day or else
a_integer = Month_day_year or else
a_integer = Day_month or else
a_integer = Month_year
end
is_month (a_string: STRING): BOOLEAN
-- Does a_string represent a month?
do
Result := months_text.has (a_string.as_upper) or else
long_months_text.has (a_string.as_upper)
end
is_weekday (a_string: STRING): BOOLEAN
-- Does `a_string' represent a weekday?
do
Result := days_text.has (a_string.as_upper) or else
long_days_text.has (a_string.as_upper)
end
get_month (a_month: STRING): INTEGER
-- Number of the `a_month'
require
is_month: is_month (a_month)
do
if months_text.has (a_month.as_upper) then
Result := months_text.index_of (a_month.as_upper, 1)
else
Result := long_months_text.index_of (a_month.as_upper, 1)
end
end
end

View File

@@ -0,0 +1,397 @@
note
description: "[
Utility class for converting {YMD_TIME}'s (i.e. dates) to and from
strings based on a selected `format'. While the string given
by feature `as_string' is set based on the format, the parsing
of a string to a date in feature `to_ymd_time' is more relaxed.
]"
author: "Jimmy J. Johnson"
copyright: "Copyright 2009, Jimmy J. Johnson"
license: "Eiffel Forum License v2 (see forum.txt)"
URL: "$URL:$"
date: "$Date: 2009-06-25 21:37:23 -0400 (Thu, 25 Jun 2009) $"
revision: "$Revision: 7 $"
class
YMD_TIME_FORMATTER
inherit
YMD_TIME_FORMAT_CONSTANTS
redefine
default_create
end
create
default_create
feature -- Initialization
default_create
-- Create an instance to parse dates in "dd mmm yy" format.
do
set_separator (" ")
end
feature -- Access
separator: STRING
-- The character (or string) placed between the day, month, year, etc.
to_ymd_time (a_string: STRING): like time_anchor
-- Parse `a_string'
require
string_exists: a_string /= Void
is_string_valid: is_valid (a_string)
do
Result := parsed (a_string)
ensure
result_exists: Result /= Void
end
to_string (a_ymd_time: like time_anchor): STRING
-- The complete string representation of `a_ymd_time'.
require
ymd_time_exists: a_ymd_time /= Void
do
create Result.make (20)
inspect format
when Day_month_year then
if is_weekday_included then
Result.append (weekday_string (a_ymd_time))
Result.append (", ")
end
Result.append (day_string (a_ymd_time))
Result.append (separator)
Result.append (month_string (a_ymd_time))
Result.append (separator)
Result.append (year_string (a_ymd_time))
when Year_month_day then
when Month_day_year then
when Month_year then
when Day_month then
else
check
should_not_happen: False
-- because format must be one of these
end
end
end
year_string (a_ymd_time: like time_anchor): STRING
-- The string representation of `year' feature of `a_ymd_time'.
-- Will be shortened to two characters if `is_short_format'.
do
create Result.make(4)
Result.append_integer (a_ymd_time.year)
if is_short_format then
if a_ymd_time.year < 10 then
Result.keep_tail (1)
if is_zero_padded then
Result.prepend ("0")
end
else
Result.keep_tail (2)
end
else
if is_zero_padded then
if a_ymd_time.year < 10 then
Result.prepend ("000")
elseif a_ymd_time.year < 100 then
Result.prepend ("00")
elseif a_ymd_time.year < 1000 then
Result.prepend ("0")
end
end
end
ensure
valid_length_if_short: is_short_format implies Result.count <= 2
end
month_string (a_ymd_time: like time_anchor): STRING
-- The string representation of `month' feature of `a_ymd_time'.
require
ymd_time_exists: a_ymd_time /= Void
do
create Result.make (10)
if is_month_numeric then
if is_zero_padded and a_ymd_time.month < 10 then
Result.append ("0")
end
Result.append_integer (a_ymd_time.month)
else
if is_short_format then
Result.append (months_text.i_th (a_ymd_time.month))
else
Result.append (long_months_text.i_th (a_ymd_time.month))
end
end
end
day_string (a_ymd_time: like time_anchor): STRING
-- The string representation of `day' feature of `a_ymd_time'.
require
ymd_time_exists: a_ymd_time /= Void
do
create Result.make (2)
if is_zero_padded and a_ymd_time.day < 10 then
Result.append ("0")
end
Result.append_integer (a_ymd_time.day)
end
weekday_string (a_ymd_time: like time_anchor): STRING
-- The string repesentation of the `weekday' of `a_ymd_time'.
-- (i.e. "Sunday", "Monday, etc. or "Sun", "Mon", etc.
require
ymd_time_exists: a_ymd_time /= Void
do
create Result.make (15)
inspect a_ymd_time.weekday
when 1 then Result.append ("Sunday")
when 2 then Result.append ("Monday")
when 3 then Result.append ("Tuesday")
when 4 then Result.append ("Wednesday")
when 5 then Result.append ("Thursday")
when 6 then Result.append ("Friday")
when 7 then Result.append ("Saturday")
else
check
should_not_happen: False
-- because `weekday' ranges from 1 to 7.
end
end
if is_short_format then
Result.keep_head (3)
end
end
feature -- Element change
set_separator (a_string: STRING)
-- Set `separator' to `a_string'.
require
separator_exists: a_string /= Void
do
separator := a_string
ensure
seperator_set: separator = a_string
end
set_format (a_format: INTEGER)
-- Change `format'.
-- The values are in YMD_TIME_FORMAT_CONSTANTS
require
valid_format: is_valid_format (a_format)
do
format := a_format
end
set_show_weekday
-- Include the day of the week in the output string.
do
is_weekday_included := True
end
set_hide_weekday
-- Do not include the day of the week in the output string.
do
is_weekday_included := False
end
set_format_short
-- Abriviate the `month_string' (if shown as text) to three
-- characters and shorten the year to two digits.
do
is_short_format := True
end
set_format_long
-- Show the `month_string' (if shown as text) to the complete
-- (unabriviated) word and show the year as four digits.
do
is_short_format := False
end
set_month_numeric
-- Make the month appear as digits, not text.
do
is_month_numeric := True
ensure
showing_month_as_digits: is_month_numeric
end
set_month_text
-- Make the month appear as text.
-- It may be full text or abbriviated depending on `is_format_short'.
do
is_month_numeric := False
ensure
showing_month_as_text: not is_month_numeric
end
set_pad_zeros
-- Make sure the `day_string', `year_string', and `month_string' (when
-- `is_month_numeric') are padded with leading zeros when necessary.
-- For example, in numeric form "9 Jan 2004" may be shown as "09/01/04".
do
is_zero_padded := True
ensure
zero_padding_set: is_zero_padded
end
set_hide_zeros
-- Do not pad numeric values with leading zeros.
do
is_zero_padded := False
ensure
not_padded: not is_zero_padded
end
feature -- Basic operations
save_format
-- Save the `format' for restoration later.
do
saved := format
ensure
format_saved: saved = format
end
restore_format
-- Reset `format' to the value `saved' by a call to `save_format'.
do
format := saved
ensure
format_restored: format = saved
end
feature -- Query
is_valid (a_string: STRING): BOOLEAN
-- Is `a_string' convertable to a date?
require
string_exists: a_string /= Void
do
Result := parsed (a_string) /= Void
ensure
definition: Result implies parsed (a_string) /= Void
end
is_weekday_included: BOOLEAN
-- Is the day of week (ie "Monday") in ymd_time string.
is_short_format: BOOLEAN
-- Is the year two digits instead of four and
-- is the month abriviated?
is_month_numeric: BOOLEAN
-- Is the `month_string' shown as digits? (As opposed to a
-- textual representation such as "January".)
is_zero_padded: BOOLEAN
-- Are digital values to be padded with leading zero's if
-- shorter than normal?
is_index_in_day_string (a_ymd_time: like time_anchor; a_index: INTEGER): BOOLEAN
require
ymd_time_exists: a_ymd_time /= Void
-- index_large_enough: a_index >= 1
local
s, ds: STRING
i: INTEGER
do
s := to_string (a_ymd_time)
ds := day_string (a_ymd_time)
i := s.substring_index (ds, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + ds.count-1
end
end
is_index_in_month_string (a_ymd_time: like time_anchor; a_index: INTEGER): BOOLEAN
require
ymd_time_exists: a_ymd_time /= Void
local
s, ms: STRING
i: INTEGER
do
s := to_string (a_ymd_time)
ms := month_string (a_ymd_time)
i := s.substring_index (ms, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + ms.count-1
end
end
is_index_in_year_string (a_ymd_time: like time_anchor; a_index: INTEGER): BOOLEAN
local
s, ys: STRING
i: INTEGER
do
s := to_string (a_ymd_time)
ys := year_string (a_ymd_time)
i := s.substring_index (ys, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + ys.count-1
end
end
is_index_in_weekday_string (a_ymd_time: like time_anchor; a_index: INTEGER): BOOLEAN
local
s, wds: STRING
i: INTEGER
do
s := to_string (a_ymd_time)
wds := weekday_string (a_ymd_time)
i := s.substring_index (wds, 1)
if i > 0 then
Result := a_index >= i and a_index <= i + wds.count-1
end
end
feature {NONE} -- Implementation
parsed (a_string: STRING): like time_anchor
-- Attemp to convert `a_string' to a {YMD_TIME}, returning
-- Void if unable.
require
string_exists: a_string /= Void
string_has_length: a_string.count >= 1
local
p: YMD_TIME_PARSER
do
create p
-- p.set_format (format)
-- p.parse_string (a_string)
-- Result := p.last_value
check
fix_me: False then
end
end
format: INTEGER
saved: INTEGER
-- used to save the format.
feature {NONE} -- Anchors (for covariant redefinitions)
time_anchor: YMD_TIME
-- Not to be called; just used to anchor types.
require
not_callable: False
do
check
do_not_call: False then
-- Because gives no info; simply used as anchor.
end
end
invariant
valid_ymd_time_format: is_valid_format (format)
end

View File

@@ -0,0 +1,68 @@
note
description: "[
Utility class for converting {YMDHMS_DURATION}'s to and from
strings based on a selected `format'. While the string given
by feature `as_string' is set based on the format, the parsing
of a string to a date in feature `to_ymdhms_duration' is more
relaxed.
]"
author: "Jimmy J. Johnson"
copyright: "Copyright 2009, Jimmy J. Johnson"
license: "Eiffel Forum License v2 (see forum.txt)"
URL: "$URL:$"
date: "$Date: 2009-06-25 21:37:23 -0400 (Thu, 25 Jun 2009) $"
revision: "$Revision: 7 $"
class
YMDHMS_DURATION_FORMATTER
inherit
HMS_DURATION_FORMATTER
rename
to_string as time_string,
set_separator as set_time_separator,
separator as time_separator,
string_to_duration as hms_string_to_duration,
format as hms_format
redefine
default_create
end
YMD_DURATION_FORMATTER
rename
to_string as date_string,
set_separator as set_date_separator,
separator as date_separator,
string_to_duration as ymd_string_to_duration,
format as ymd_format
redefine
default_create
end
create
default_create
feature -- Initialization
default_create
--
do
Precursor {HMS_DURATION_FORMATTER}
Precursor {YMD_DURATION_FORMATTER}
end
feature -- Access
to_string (a_duration: YMDHMS_DURATION): STRING
-- the whole duration as a string
require
duration_exists: a_duration /= Void
do
create Result.make (30)
Result.append (date_string (a_duration))
Result.append (" ")
Result.append (time_string (a_duration))
end
end -- class YMDHMS_DURATION_FORMATTER

View File

@@ -0,0 +1,126 @@
note
description: "[
Utility class for converting {YMDHMS_TIME}'s (i.e. date/times) to and from
strings based on a selected `format'. While the string given
by feature `as_string' is set based on the format, the parsing
of a string to a date in feature `to_ymd_time' is more relaxed.
]"
author: "Jimmy J. Johnson"
copyright: "Copyright 2009, Jimmy J. Johnson"
license: "Eiffel Forum License v2 (see forum.txt)"
URL: "$URL:$"
date: "$Date: 2009-06-25 21:37:23 -0400 (Thu, 25 Jun 2009) $"
revision: "$Revision: 7 $"
class
YMDHMS_TIME_FORMATTER
inherit
HMS_TIME_FORMATTER
rename
set_separator as set_time_separator,
separator as time_separator
redefine
default_create,
to_string,
time_anchor
end
YMD_TIME_FORMATTER
rename
set_separator as set_date_separator,
separator as date_separator
redefine
default_create,
to_string,
time_anchor
end
create
default_create
feature {NONE} -- Initialization
default_create
do
Precursor {HMS_TIME_FORMATTER}
Precursor {YMD_TIME_FORMATTER}
end
feature -- Access
to_string (a_time: like time_anchor): STRING
-- the whole date as a string
do
create Result.make (30)
if not is_date_hidden then
Result.append (Precursor {YMD_TIME_FORMATTER} (a_time))
Result.append (" ")
end
if not is_time_hidden then
Result.append (Precursor {HMS_TIME_FORMATTER} (a_time))
end
end
feature -- Status report
is_time_hidden: BOOLEAN
-- Will `to_string' not include the time?
is_date_hidden: BOOLEAN
-- Will `to_string' not include the date?
feature -- Status setting
hide_time
-- Make `to_string' produce a string showing the date only;
-- the time portion will not show.
do
is_time_hidden := True
is_date_hidden := False
ensure
time_is_hidden: is_time_hidden
date_is_shown: not is_date_hidden
end
hide_date
-- Make `a_string' produce a string showing the time only;
-- the date portionn will not show.
do
is_date_hidden := True
is_time_hidden := False
ensure
date_is_hidden: is_date_hidden
time_is_shown: not is_time_hidden
end
show_date_and_time
-- Make `to_string' produce a string showing both the date
-- portion and the time portion. This is the default.
do
is_date_hidden := False
is_time_hidden := False
ensure
date_is_shown: not is_date_hidden
time_is_shown: not is_time_hidden
end
feature {NONE} -- Anchors (for covariant redefinitions)
time_anchor: YMDHMS_TIME
-- Not to be called; just used to anchor types.
require else
not_callable: False
do
check
do_not_call: False then
-- Because gives no info; simply used as anchor.
end
end
invariant
not_both_date_and_time_hidden: not (is_date_hidden and is_time_hidden)
end