tzone.sa
Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
-------------------------> GNU Sather - sourcefile <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute and/or modify it under the terms of the GNU Library General --
-- Public License (LGPL) as published by the Free Software Foundation; --
-- either version 2 of the license, or (at your option) any later version. --
-- This library is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details. --
-- The license text is also available from: Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --
--------------> Please email comments to <bug-sather@gnu.org> <--------------
class TIME_ZONE < $BINARY, $STR
class TIME_ZONE < $BINARY, $STR is
-- This class is the descriptor to be used when calculating local time
-- from UTC and vice-versa.
-- Version 1.0 Feb 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 20 Feb 98 kh Original using ISO/IEC 14652 spec.
include BINARY ;
private attr std_name : STR ;
private attr std_offset : ELAPSED ;
private attr add_std_offset : BOOL ;
private attr dst_name : STR ;
private attr dst_offset : ELAPSED ;
private attr add_dst_offset : BOOL ;
private attr rules : FLIST{TZONE_RULE} ;
create(
sname : STR,
std_off : ELAPSED,
std_add : BOOL,
dst : STR,
dst_off : ELAPSED,
dst_add : BOOL,
rules : FLIST{TZONE_RULE}
) : SAME is
-- This creation routine is provided for use by the program reading
-- source text to create this object.
me : SAME := new ;
me.std_name := sname ;
me.std_offset := std_off ;
me.add_std_offset := std_add ;
me.dst_name := dst ;
if dst_off = #ELAPSED(0,0) then
me.dst_offset := std_off + ELAPSED::one_hour
else
me.dst_offset := dst_off
end ;
me.add_dst_offset := dst_add ;
me.rules := rules.copy ;
return me
end ;
build(
index : BIN_CURSOR,
lib : LIBCHARS
) : SAME
pre ~void(index)
and ~index.is_done
post true
is
-- This routine reads its component values from the binary string
-- indicated and then returns the new time zone object.
me : SAME := new ;
me.rules := FLIST{TZONE_RULE}::create ;
me.std_name := index.get_sized.str(lib) ;
me.std_offset := ELAPSED::build(index) ;
-- always less than a day - 0 days
me.add_std_offset := BOOL::build(index) ;
me.dst_name := index.get_sized.str(lib) ;
me.dst_offset := ELAPSED::build(index) ;
-- always less than a day - 0 days
me.add_dst_offset := BOOL::build(index) ;
loc_cnt : CARD := index.get_item.card ; -- the number of rules
loop
loc_cnt.times! ;
if index.is_done then
return void
end ;
loc_rule : TZONE_RULE := TZONE_RULE::build(index) ;
me.rules := me.rules.push(loc_rule)
end ;
return me
end ;
build(
index : BIN_CURSOR
) : SAME
pre ~void(index)
and ~index.is_done
post true
is
-- This routine reads its component values from the binary string
-- indicated and then returns the new time zone object.
return build(index,LIBCHARS::default)
end ;
binstr : BINSTR
pre ~void(self)
post ~void(result)
is
-- This routine creates a binary string form of representation of self.
loc_str : BINSTR := BINSTR::create + std_name.binstr.sized ;
loc_str := loc_str + std_offset.binstr ;
loc_str := loc_str + add_std_offset.binstr ;
loc_str := loc_str + dst_name.binstr.sized ;
loc_str := loc_str + dst_offset.binstr ;
loc_str := loc_str + add_dst_offset.binstr ;
loc_str := loc_str + OCTET::create(rules.size) ;
if rules.size > 0 then
loop
loc_str := loc_str + rules.elt!.binstr
end
end ;
return loc_str
end ;
private summer_time(
stamp : TIME_STAMP
) : BOOL is
-- This private predicate returns true if and only if the given
-- time-stamp indicates that it is summer-time in the current culture.
rule : TZONE_RULE ;
loop
rule := rules.elt! ;
if rule.applies(stamp) then
return rule.is_summer(stamp)
end
end ;
return false -- if not defined this is default
end ;
is_west_of_UTC(
tstamp : TIME_STAMP
) : BOOL is
-- This predicate returns true if and only if the location of the current
-- culture is west of UTC at the given time, otherwise false.
if summer_time(tstamp) then
return ~add_dst_offset
else
return ~add_std_offset
end
end ;
is_west_of_UTC : BOOL is
-- This predicate returns true if and only if the location of the current
-- culture is west of UTC at the time of calling, otherwise false.
return is_west_of_UTC(TIME_STAMP::now)
end ;
time_difference(
tstamp : TIME_STAMP
) : ELAPSED
pre ~void(self)
post ~void(result)
is
-- This routine returns the time difference between the current cultural
-- location and UTC at the given time. This is ALWAYS a positive value.
if summer_time(tstamp) then
return dst_offset
else
return std_offset
end
end ;
time_difference : ELAPSED
pre ~void(self)
post ~void(result)
is
-- This routine returns the time difference between the current cultural
-- location and UTC. This is ALWAYS a positive value.
return time_difference(TIME_STAMP::now)
end ;
str(
stamp : TIME_STAMP,
lib : LIBCHARS
) : STR
pre ~void(stamp)
and ~void(lib)
and ~void(self)
post (result.size = 3)
or (result.size = 4)
is
-- This routine returns the current string representation in the given
-- repertoire and encoding for the time zone, dependent on the date and time!
if summer_time(stamp) then
return dst_name.copy
else
return std_name.copy
end
end ;
str(
lib : LIBCHARS
) : STR
pre ~void(self)
and ~void(lib)
post (result.size = 3)
or (result.size = 4)
is
-- This routine returns the current string representation in the given
-- repertoire and encoding for the time zone, dependent on the date and time!
return str(TIME_STAMP::now,lib)
end ;
str(
stamp : TIME_STAMP
) : STR
pre ~void(stamp)
and ~void(self)
post (result.size = 3)
or (result.size = 4)
is
-- This routine returns the current string representation in the given
-- repertoire and encoding for the time zone, dependent on the date and time!
return str(stamp,LIBCHARS::default)
end ;
str : STR
pre ~void(self)
post (result.size = 3)
or (result.size = 4)
is
-- This routine returns the current string representation using the
-- default repertoire and encoding for the time zone, dependent on the date
-- and time!
return str(TIME_STAMP::now,LIBCHARS::default)
end ;
end ; -- TIME_ZONE