mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2025-12-07 15:22:31 +01:00
Author:admin
Date:2008-09-17T13:53:28.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@3 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
[[Property:title|Absolute time]]
|
||||
[[Property:weight|0]]
|
||||
The classes dealing with date and those dealing with time have almost the same construction. At the top of the hierarchy are the constants and the notion of value ([[ref:libraries/time/reference/time_value_chart|TIME_VALUE]] , [[ref:libraries/time/reference/date_value_chart|DATE_VALUE]] , [[ref:libraries/time/reference/date_time_value_chart|DATE_TIME_VALUE]] ). From this notion come two kinds of heirs which are the absolute notion of time (classes [[ref:libraries/time/reference/date_chart|DATE]] , [[ref:libraries/time/reference/time_chart|TIME]] and [[ref:libraries/time/reference/date_time_chart|DATE_TIME]] ) and the notion of duration (classes [[ref:libraries/time/reference/date_duration_chart|DATE_DURATION]] , [[ref:libraries/time/reference/time_duration_chart|TIME_DURATION]] , [[ref:libraries/time/reference/date_time_duration_chart|DATE_TIME_DURATION]] ).
|
||||
|
||||
[[ref:libraries/time/reference/date_chart|DATE]] , [[ref:libraries/time/reference/time_chart|TIME]] and [[ref:libraries/time/reference/date_time_chart|DATE_TIME]] inherit from the deferred class <eiffel>ABSOLUTE</eiffel>. It implies that instances of these classes are used as absolutes. We can imagine an oriented axis on which are reported values. <eiffel>ABSOLUTE </eiffel>inherits <eiffel>COMPARABLE</eiffel>, there is a complete order inside the class and its heir. <eiffel>ABSOLUTE</eiffel> is a client of <eiffel>DURATION</eiffel>, so that each instance of <eiffel>ABSOLUTE </eiffel>is linked with the duration between the origin and itself.
|
||||
|
||||
The default way to compare absolute objects is to compare their respective duration to each other.
|
||||
|
||||
==TIME==
|
||||
|
||||
[[ref:libraries/time/reference/time_chart|TIME]] deals with hour, minute and second. Is is possible to use more precision for time (there is no limit inside the class). See More precision in <eiffel>TIME</eiffel> for documentation. This section deals only with second.
|
||||
|
||||
====Creation====
|
||||
|
||||
There are three ways to create an instance of the class <eiffel>TIME</eiffel>: by choosing the time (make), by getting the time from the system (make_now), or by choosing the number of seconds elapsed from the origin (make_by_seconds). The arguments of make and make_by_seconds have to respect the range of a day (see preconditions).
|
||||
|
||||
====Origin and cyclic representation====
|
||||
|
||||
The origin is 0 hour 0 minute and 0 second. Notion of time is relative to a day in a cyclic representation: days begin at 0:0:0 and end at 23:59:59. If a second is added to 23:59:59 then the result will be 0:0:0. Subtracting a minute to 0:0:0 will yield 23:59:0.
|
||||
|
||||
====Comparison====
|
||||
|
||||
Instances of [[ref:libraries/time/reference/time_chart|TIME ]] may be compared. Functions <, + > and >= are available. Function is_equal must be use to test equality. = will compare references.
|
||||
|
||||
====Measurement====
|
||||
|
||||
The duration linked to an instance of [[ref:libraries/time/reference/time_chart|TIME]] (attribute duration) is an instance of [[ref:libraries/time/reference/time_duration_chart|TIME_DURATION]] . It is the duration from the origin until the current time. The function seconds returns the number of seconds since the origin. This function may be useful to get the number of seconds between two events.The feature - creates an interval between two instances of <eiffel>TIME</eiffel>. The duration of this interval is given by the function duration. However, this duration is not canonical (See [[Duration|Duration]] for precisions). In <eiffel>TIME</eiffel>, the feature relative_duration returns the same duration, but more efficiently and also it is canonical.
|
||||
|
||||
====Operations====
|
||||
* Set directly hour, minute and second with set_hour, set_minute and set_second. Arguments must satisfy the rules of creation.
|
||||
* Adding hours, minutes and seconds with features hour_add, minute_add and second_add. Features add and + take an instance of TIME_DURATION as an Page 3 argument and add it to the current time.
|
||||
* Moving to the next or the previous hour, minute or second with features hour_forth, hour_back, minute_forth, minute_back, second_forth and second_back. It is faster to use these features rather than those above (hour_back <-> hour_add (-1)).
|
||||
|
||||
==DATE==
|
||||
|
||||
<eiffel>DATE</eiffel> deals with year, month and day. It is more complicated since there is no regular period in dates: each month contains its own total of days and there are leap years. That is why some peculiarities appear while manipulating objects of this class. There is no limit for a date (inside the class). The only limit comes from INTEGER representation. If INTEGER size is 32 bits (most common case), and as long as the basic unit is a day, the range for a date is from (- 2^31) to 2^31 (days), i.e. 5.8 million years from the origin.
|
||||
|
||||
====Creation====
|
||||
|
||||
There are also three ways to create an instance of the class <eiffel>DATE</eiffel>: by choosing the date (make, make_month_day_year, make_day_month_year), by getting the date from the system (make_now), or by choosing the number of days elapsed from the origin (make_by_days). The arguments of each creation procedure have to respect the common range (See preconditions).
|
||||
|
||||
====Origin====
|
||||
|
||||
The origin is 01/01/1600.
|
||||
|
||||
====Comparison====
|
||||
|
||||
Instances of <eiffel>DATE</eiffel> may be compared. Functions <, + > and >= are available. Function is_equal must be use to test equality, = will compare references.
|
||||
|
||||
====Measurement====
|
||||
|
||||
Each instance of <eiffel>DATE</eiffel> has a function (duration) which returns the duration since the origin until the current date (it is an instance of DATE_DURATION). This duration is definite, i.e. it contains only days (See below). However, it may be useful to deal directly with days (no need of DATE_DURATION). In this case, the function days of <eiffel>DATE</eiffel> yields the number of days since origin.
|
||||
|
||||
====Status Report====
|
||||
|
||||
Much information may be gotten from functions written in this part. Most of them are used within the class, but they are exported at the same time.
|
||||
|
||||
====Operations====
|
||||
|
||||
<eiffel>DATE</eiffel> operations looks like <eiffel>TIME</eiffel> operations:
|
||||
* Setting directly year, month and day with set_year, set_month and set_day. Arguments must satisfy the rules of creation. These rules are more complicated than those of <eiffel>TIME</eiffel>. For example it is not allowed to set day to 31 if the current month is April, whereas it is allowed if the month is January. It is the same rules as for make. The same thing for years: It is not allowed to set year to a non-leap year if the current date is February 29th of a leap year. However, two features are available to set month and year even if day is too large: set_month_cut_days and set_year_cut_days will cut day down to the largest value allowed.
|
||||
* Adding years, months and days with features year_add, month_add and day_add. There is no requirement to add a year or a month. However, these features have to return a correct result, i.e. day is checked before each addition-. Adding one month to August 31st will yield September 30th. 31 is cut to 30 since there are only 30 days in September. Features add and + take an instance of DATE_DURATION in argument and add it to the current date. It is written so that years and months are added first, the days last.(see DATE_DURATION below)
|
||||
* Moving to the next or the previous year, month or day with features year_forth, year_back, month_forth, month_back, day_forth and day_back. It is the same but faster to use these features rather than those upper (year_back <-> year_add (-1)).
|
||||
* Features relative_duration and definite_duration return the duration between the current date and the argument. The first one returns a result which is canonical (See definitions below), while the second one returns a definite result but may be not canonical.
|
||||
|
||||
For example, date1 is April 20th and date2 is May 28th. Both features will yield instances of DURATION; however, relative_duration will yield 1 month and 8 days whereas definite_duration will yield 38 days.
|
||||
|
||||
==DATE_TIME==
|
||||
|
||||
The aim is to gather the time with the date. <eiffel>DATE_TIME</eiffel> is client of <eiffel>TIME</eiffel> and <eiffel>DATE</eiffel> (see inheritance relation). Some features from <eiffel>DATE</eiffel> and <eiffel>TIME</eiffel> are re-written since they are useful within the class. Many other features may be called indirectly with the correct attribute (time or date).
|
||||
|
||||
====Creation====
|
||||
|
||||
There are still several ways to create an instance:
|
||||
* by choosing value for all the attributes of the date and the time (make).
|
||||
* by getting the time from the system (make_now).
|
||||
* by gathering an instance of <eiffel>DATE</eiffel> with an instance of <eiffel>TIME</eiffel> (make_by_date_time).This feature copies only the references of its arguments, so that if the time (or the date) is changed, the instance previously initialized will be also changed. If this effect has to be avoided, cloning the arguments is required.
|
||||
* by encapsulating an instance of <eiffel>DATE</eiffel> (make_by_date). The attribute time is set to the origin, i.e. 0:0:0.
|
||||
|
||||
The attribute date is set with the same reference as the argument (See comment of the previous section).
|
||||
|
||||
====Access====
|
||||
|
||||
To make it easier calls to features of <eiffel>TIME</eiffel> and <eiffel>DATE</eiffel>, the most useful access features are written as features in <eiffel>DATE_TIME</eiffel> (days, seconds and their associated duration date_duration and time_duration).
|
||||
|
||||
====Comparison====
|
||||
|
||||
Instances of <eiffel>DATE_TIME</eiffel> are totally ordered (the class inherit from <eiffel>ABSOLUTE</eiffel>). Functions <, + > and >= are available. Function is_equal must be used to test equality, = will compare references.
|
||||
|
||||
====Measurement====
|
||||
|
||||
Function duration gathers functions duration from the attributes time and date. The result is an instance of <eiffel>DATE_TIME_DURATION</eiffel>.
|
||||
|
||||
====Element change====
|
||||
|
||||
It is possible to change reference of time and date with the features set_time and set_date. To change only one element (for example hour), features from <eiffel>TIME</eiffel> or <eiffel>DATE</eiffel> have to be used.
|
||||
|
||||
====Operations====
|
||||
|
||||
Addition of hours, minutes and seconds are available directly in the class.The reason is that adding one second may have a consequence on the date. Using second_add from <eiffel>TIME</eiffel> is also possible but the date will not be modified in the case time makes a cycle. It is of course the same for minute and hour. day_add is also available directly since it is frequently used within the class.
|
||||
|
||||
Features + and add take an instance of <eiffel>DATE_TIME_DURATION</eiffel> in arguments. The date duration is added first then the time duration. Adding the time duration first would have yield some different result as in this example: the current date is August 30th 23:59:59. The duration to add is one month and one second. Feature add returns October 1st 0:0:0, whereas adding the second first would return September 30th 0:0:0! The same difference occurs with leap years.
|
||||
|
||||
Feature relative_duration and definite_duration returns the duration between the current date (with time) and the argument. The first one returns a result which is canonical (see definitions below), while the second one returns a result definite but may be not canonical. It is the same notion than in <eiffel>DATE</eiffel>.
|
||||
|
||||
==DATE and DATE_TIME==
|
||||
|
||||
Another way to process would have been to make <eiffel>DATE_TIME</eiffel> inherit from <eiffel>DATE</eiffel>,as long as <eiffel>DATE_TIME</eiffel> is a <eiffel>DATE</eiffel>, with more precision. The choice was to have a client relation between them. Otherwise <eiffel>DATE</eiffel> should have known the existence of <eiffel>DATE_TIME</eiffel>, and many assignment attempts would have been useful in features such as infix +. So <eiffel>DATE_TIME</eiffel> is client of <eiffel>DATE</eiffel>.
|
||||
|
||||
However, it could be useful to mix instances of <eiffel>DATE</eiffel> of <eiffel>DATE_TIME</eiffel>. As <eiffel>DATE_TIME</eiffel> is client of <eiffel>DATE</eiffel> with its attribute date, it is easy to get only the date from instances of <eiffel>DATE_TIME</eiffel>. On the other way features are available to convert objects from <eiffel>DATE</eiffel> to <eiffel>DATE_TIME</eiffel>. In class <eiffel>DATE</eiffel>, feature to_date_time builds an instance of <eiffel>DATE_TIME</eiffel> with the origin of time (0,0,0). In the class DATE_TIME, the creation procedure make_by_date has the same effect. (The same feature exists for duration, replacing origin by zero).
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
[[Property:title|DATE / TIME to STRING Conversion]]
|
||||
[[Property:weight|3]]
|
||||
The following table lists format conversion codes.
|
||||
{|
|
||||
|-
|
||||
| '''Code'''
|
||||
| '''Description'''
|
||||
|-
|
||||
| dd
|
||||
| day - numeric
|
||||
|-
|
||||
| [0]dd
|
||||
| day - numeric (padded with '0' to 2 figures)
|
||||
|-
|
||||
| ddd
|
||||
| day - text (3 letters e.g "Mon", "Tue")
|
||||
|-
|
||||
| yyyy
|
||||
| year - numeric (4 figures)
|
||||
|-
|
||||
| yy
|
||||
| year - numeric (2 figures)
|
||||
|-
|
||||
| mm
|
||||
| month - numeric
|
||||
|-
|
||||
| [0]mm
|
||||
| month - numeric (padded with '0' to 2 figures)
|
||||
|-
|
||||
| mmm
|
||||
| month - text (3 letters e.g "Dec", "Jan")
|
||||
|-
|
||||
| hh
|
||||
| hour - numeric (24 hour clock scale by default)
|
||||
|-
|
||||
| [0]hh
|
||||
| hour - numeric (padded with '0' to 2 figures)
|
||||
|-
|
||||
| hh12
|
||||
| hour - numeric (12 hour clock scale)
|
||||
|-
|
||||
| mi
|
||||
| minute - numeric
|
||||
|-
|
||||
| [0]mi
|
||||
| minute - numeric (padded with '0' to 2 figures)
|
||||
|-
|
||||
| ss
|
||||
| seconds - numeric
|
||||
|-
|
||||
| [0]ss
|
||||
| seconds - numeric (padded with '0' to 2 figures)
|
||||
|-
|
||||
| ff<n>
|
||||
| fractional seconds - numeric (precise to <n> figures)
|
||||
|-
|
||||
| ':', '/', '-' and ','
|
||||
| separators e.g. "03/Aug/97"
|
||||
|}
|
||||
These are some examples of output with their associated format code:
|
||||
{|
|
||||
|-
|
||||
| '''Code'''
|
||||
| '''Output'''
|
||||
|-
|
||||
| yy/m/dd
|
||||
| 97/8/18
|
||||
|-
|
||||
| mmm-dd-yy
|
||||
| Aug-18-97
|
||||
|-
|
||||
| dd,mm,yyyy
|
||||
| 18,Aug,1997
|
||||
|-
|
||||
| hh-mi-ss
|
||||
| 13-06-32
|
||||
|-
|
||||
| hh12,mi,ss
|
||||
| 1,06,32 pm
|
||||
|-
|
||||
| hh12:mi:ff
|
||||
| 1:06:32.25 pm
|
||||
|-
|
||||
| hh:mi:ff3
|
||||
| 13:06:32.248
|
||||
|-
|
||||
| [0]mm/dd/yy hh12:mi:ff3
|
||||
| 08/18/97 1:06:32.248 pm
|
||||
|}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
[[Property:title|Duration]]
|
||||
[[Property:weight|1]]
|
||||
<eiffel>TIME_DURATION</eiffel>, <eiffel>DATE_DURATION</eiffel> AND <eiffel>DATE_TIME_DURATION</eiffel>
|
||||
|
||||
The classes dealing with duration inherit DURATION, which inherits GROUP_ELEMENT and PART_COMPARABLE. An instance of <eiffel>TIME_DURATION</eiffel>, <eiffel>DATE_DURATION</eiffel> or <eiffel>DATE_TIME_DURATION</eiffel> is an element of a group, i.e. there is a zero and addition operations (infix +,infix -, prefix + and prefix -). Duration is used as an amount of time, without link to an origin. It may be added to the respective absolute notion (time + time_duration is possible, not time + date_time_duration nor date_time + time_duration...see classes <eiffel>TIME</eiffel>, <eiffel>DATE</eiffel> and <eiffel>DATE_TIME</eiffel>).
|
||||
|
||||
Attributes are allowed to take negative values or values which do not stand in the usual range (hour = -1, minute = 75, day = 40...). However, features are available in each class to convert instances into the usual format: functions canonical and to_canonical are present in each class. An instance is canonical (canonical = True) if its attributes stand into the usual range. For example, an instance of <eiffel>TIME_DURATION</eiffel> such as 12:-10:60 is not canonical. to_canonical will return 11:51:0. In <eiffel>DATE_DURATION</eiffel> and <eiffel>DATE_TIME_DURATION</eiffel>, these features are also present.
|
||||
|
||||
The order is partially implemented. <eiffel>TIME_DURATION</eiffel> has a complete order whereas <eiffel>DATE_DURATION</eiffel> and <eiffel>DATE_TIME_DURATION</eiffel> are more specific.
|
||||
|
||||
==TIME_DURATION==
|
||||
|
||||
====Creation====
|
||||
|
||||
Two ways are possible: by choosing the value of each attributes hour, minute and second (feature make), or by giving an amount of seconds (make_by_seconds). Any integer value is accepted. It is possible to create a duration with 1 hour and -60 minutes.
|
||||
|
||||
====Access====
|
||||
|
||||
Zero is a once feature with 0 hour, 0 minute and 0 second. The total amount of second of the current duration is the result of feature seconds_count.
|
||||
|
||||
====Comparison====
|
||||
|
||||
Instances of <eiffel>TIME_DURATION</eiffel> may be compared easily. The order is the order oft he respective total amount of second. 1:-40:0 is less than 0:0:1800, etc... Functions <, >,<= and >= are available. Is_equal tests equality, = will compare references.
|
||||
|
||||
====Element change====
|
||||
|
||||
Set directly hour, minute and second with set_hour, set_minute and set_second. Arguments do not need to satisfy any range rule.
|
||||
|
||||
====Operations====
|
||||
* Adding hours, minutes and seconds with features hour_add, minute_add and second_add.
|
||||
* <eiffel>TIME_DURATION</eiffel> inherits from GROUP_ELEMENT. infix and prefix +, infix and prefix - are available to compose instances of each other.
|
||||
|
||||
====Conversion====
|
||||
|
||||
Two features ensure a link with the notion of day: to_days returns the number of days equivalent to the current duration. For example, a duration such as 23:60:0 is equivalent to one day. For negative duration, the result is never 0. -1 hour is equivalent to -1 day (i.e. the result of the function is -1). To_days is associated with time_modulo_day. This second function returns an instance of <eiffel>TIME_DURATION</eiffel>. The result represents the difference between the current duration and the number of days yielded by to_days. It implies that the result is always positive and less than one day.
|
||||
|
||||
For example, the current duration is 25:70:600. to_days will returns 1 (one day) and time_modulo_day will return 2:20:0:. If the current duration is negative: -23:-80:300,to_days will return -2 (minus two days) and time_modulo_day will return 23:45:0.
|
||||
|
||||
Durations may be canonical or not canonical (BOOLEAN canonical). That means the features hour, minute and second are included in a particular range, or not. An instance of <eiffel>TIME_DURATION</eiffel> is canonical if:
|
||||
* in the case of a positive duration (> zero), all of the three features have to be positive or 0, minute and second less than 60.
|
||||
* in the case of a negative duration (< zero), all of the three features have to be negative or 0, minute and second strictly greater than -60. The function canonical tests if the duration is canonical or not, the function to_canonical yields a new duration equivalent to the current one and canonical.
|
||||
|
||||
==DATE_DURATION==
|
||||
|
||||
Dealing with the Gregorian calendar is not so easy because of irregularities. A duration of one month may be equal to 28 up to 31 days, depending on the current date! On the other hand, it could be useful to deal with precise duration. This point leads to an original design of the class: A separation is made between two kinds of instances.
|
||||
|
||||
The definite ones and the relative ones. The function definite which returns a BOOLEAN, is true for definite duration and false otherwise. An instance is definite if and only if its attributes month and year are 0. Then only the number of days is used. Relative (non definite) durations have their attributes year, month and day meaningful but it is then impossible to compare them to each other (is one month greater than 30 days?, is one year greater than 365 days?). The main difference appears when a duration is added to a date. In the case of a definite duration, there is no ambiguity. A given number of days are added to the date, taking care of the calendar. In the other case, the result is relative to the origin date. For example, a one month duration may be equal to 28 days if the date is in February or 31 days if the date is in August. A duration becomes definite when its attributes year and month become 0. However it is possible to deal with instances of <eiffel>DATE_DURATION</eiffel> without taking care of this distinction.
|
||||
|
||||
===Relative date_duration===
|
||||
|
||||
Relative duration cannot be compared with any other durations (including zero). The reason is simple. It is not possible to say if 30 days are less than 1 month: it depends on the date: it is true in August (in a 31 days month) and it is false in February.
|
||||
|
||||
If feature > (or <, + + is called with at least one non definite member (the current instance or the argument), the result will be always False. We may only know if two durations are equal, with the feature is_equal. It compares field by field the two durations. When adding a relative date_duration to a date, the years and the months are added first, then the date may be cut (June 31 -> June 30) and finally the days are added. For example, if one month is added to the date August 31st, the result is September 30th.
|
||||
|
||||
Nevertheless there is a way to compare relative durations: a relative date_duration may be canonical. It means that the duration has its attributes month and day in a fixed range.month must be between 1 and 12, and day larger than 1 and less than a value between 27 and 30. This value is fixed simply: (in the case of a positive duration) when setting day to 0 and adding one more month, the addition of the start date and this new duration must yield a date strictly after the final date (yielded by adding date and tested duration). For example is 0/0/30 (i.e. 0 year, 0 month and 30 days) canonical?
|
||||
* If the origin date is 01/15 (15th of January), the final date is 02/14. We cannot convert 30 days into 1 month in this case. The duration is canonical.
|
||||
* If the origin date is 04/15 (15th of April), the final date is 05/15. The duration is not canonical since it is possible to convert days into 1 month. The origin date is used to determine whether the duration is positive or not. If the final date is after the origin date the duration is positive, otherwise it is negative. That does not mean we can compare it to zero, that is only used to determine the sign of the canonical standard. If the duration is negative, it is canonical only if all the attributes are negative.
|
||||
|
||||
A way to compare two relative durations is to make them canonical from the same date, and then to compare the fields. It is the same as adding the durations to the same date, and to compare the final dates to each other.
|
||||
|
||||
===Definite date_duration===
|
||||
|
||||
Definite durations are characterized by the attribute day. Whenever a duration has its attributes year and month equal to 0, this duration is then definite. On the other hand, if one of these two attributes is not 0, the duration is not definite anymore.
|
||||
|
||||
The number of days between an origin date and the result of (date + duration) does not depend on the origin date. It is possible to compare definite date_duration to each other.The order is the one of day.
|
||||
|
||||
A definite duration may be canonical or not. It is canonical if the number of day is small enough.
|
||||
|
||||
===General description===
|
||||
|
||||
====Creation====
|
||||
|
||||
Two creation features are available: make takes three arguments (year, month and day). If year and month are null, the duration will be definite; make_by_days takes only the number of day. The duration is automatically definite.
|
||||
|
||||
====Comparison====
|
||||
|
||||
Features <, >, <= and >= are available. If both instances are definite, numbers of days are compared. If one of them is non definite, the result is False.
|
||||
|
||||
====Element change====
|
||||
|
||||
Features set_day, set_month and set_year are available to set one of these three attributes day, month, year.
|
||||
|
||||
====Operation====
|
||||
* Add years, months and days with features year_add, month_add and day_add.
|
||||
* <eiffel>DATE_DURATION</eiffel> inherits from GROUP_ELEMENT. infix and prefix +, infix and prefix - are available to compose instances of each other.
|
||||
|
||||
====Conversion====
|
||||
* to_canonical is used to get a new duration equivalent to the current one and canonical. It needs an argument from class <eiffel>DATE</eiffel>, which is the origin of calculations.
|
||||
* to_definite is used to get a new duration equivalent to the current one and definite. As with the previous feature, one argument is needed. - to_date_time is used to get an instance of <eiffel>DATE_TIME_DURATION</eiffel>. It will have the same date of the current duration and time set to zero.
|
||||
|
||||
==DATE_TIME_DURATION==
|
||||
|
||||
<eiffel>DATE_TIME_DURATION</eiffel> is client of <eiffel>DATE_DURATION</eiffel> and <eiffel>TIME_DURATION</eiffel>. Most of the common features described in <eiffel>DATE_DURATION</eiffel> are present in the class. The class deals with its attributes date and time in the same way as <eiffel>DATE_TIME</eiffel>.
|
||||
|
||||
There are, as in <eiffel>DATE_DURATION</eiffel>, definite and non definite durations. It is the date part which gives the definite non definite status. Features canonical and to_canonical are present in DATE_TIME_DURATION. They have to deal with the attributes time.
|
||||
|
||||
====Creation====
|
||||
|
||||
There are still several ways to create an instance:
|
||||
* by choosing values for all the attributes of date and time (make). - by choosing a value for day and values for all the attributes of time. The instance is then definite (make_definite).
|
||||
* by gathering an instance of <eiffel>DATE</eiffel> with an instance of <eiffel>TIME</eiffel> (make_by_date_time). This feature copies the references of its arguments, so that if the time (or the date) is changed, the instance previously initialized will be also changed. If this effect has to be avoided, the use of clones is required.
|
||||
* by encapsulating an instance of <eiffel>DATE</eiffel> (make_by_date). The attribute time is set to zero, i.e. 0:0:0. The attribute date is set with the same reference than the argument.
|
||||
|
||||
====Access====
|
||||
|
||||
Seconds_count is the amount of seconds of the time part only. To get the total amount of seconds of the current duration, first shift it to a definite duration, then multiply day by the number of seconds in day and add to it seconds_count. Take care that the duration is not more than 68 years. If it is, the number of seconds will be larger than 2 billion, which is the upper limit for INTEGER (4 bytes).
|
||||
|
||||
====Comparison====
|
||||
|
||||
The rules are the same than those for <eiffel>DATE_DURATION</eiffel>. Features <, >,<= and >= are available. If both instances are definite, numbers of days are compared. If one of them is non definite, the result is False.
|
||||
|
||||
====Element change====
|
||||
|
||||
It is possible to change reference of time and date with the features set_time and set_date. To change only one element (for example hour), features from <eiffel>TIME_DURATION</eiffel> or <eiffel>DATE_DURATION</eiffel>have to be used.
|
||||
|
||||
====Operation====
|
||||
* <eiffel>DATE_TIME_DURATION</eiffel> inherits from GROUP_ELEMENT. infix and prefix +, infix and prefix - are available to compose instances to each other.
|
||||
* Only day_add is present. To add only one element, features from <eiffel>TIME_DURATION</eiffel> or <eiffel>DATE_DURATION</eiffel> have to be used.
|
||||
|
||||
====Conversion====
|
||||
* canonical and to_canonical are available in the class. To be canonical an instance of the class must have its attributes time and date canonical. Then time must have the same sign than the one of the current duration. The sign of the current instance is determined by adding it to the argument (from <eiffel>DATE_TIME</eiffel>). That will yield a final date. If this final date is after the origin (= the argument), the current duration is considered positive. Otherwise, it is considered negative. Finally time must be less than one day (if positive) or more than minus one day (if negative). To_canonical returns a duration equivalent to the current one (for the argument) and canonical.
|
||||
* time_to_canonical looks like to_canonical but focuses mainly on time. It requires a definite duration so that it is possible to compare it to zero. It yields a definite duration equivalent to the current one with a canonical time. hour is then cut so that it stands in the range of one day (0 to 23 if positive and -23 to 0 if negative). The attributes day is also modified to keep the result equivalent to the current duration.time_to_canonical does not need any argument because only time and day are modified.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
[[Property:title|Interval]]
|
||||
[[Property:weight|2]]
|
||||
Class <eiffel>INTERVAL</eiffel> deals with intervals between two instances of the same class which conform to<eiffel> ABSOLUTE</eiffel> ( <eiffel>DATE</eiffel>, <eiffel>TIME</eiffel>, <eiffel>DATE_TIME</eiffel>). The notions of interval is directly linked with the notion of order.
|
||||
|
||||
The <eiffel>start_bound</eiffel> must be before the <eiffel>end_bound</eiffel>.
|
||||
|
||||
====Creation====
|
||||
|
||||
The features <eiffel>make</eiffel>, <eiffel>set_start_bound</eiffel> and <eiffel>set_end_bound</eiffel> take clones of their arguments, so that if these arguments are changed, the interval previously created is not.
|
||||
|
||||
It would have been possible to create intervals with references to date or time, but a modification of the dates would have been effective in the interval so that only the invariant would have been able to check if the <eiffel>start_bound</eiffel> is still before the <eiffel>end_bound</eiffel>.
|
||||
|
||||
====Interval measurement====
|
||||
|
||||
The measure of intervals is made by duration: the result is an instance of the class <eiffel>DURATION</eiffel>. However, as <eiffel>DURATION</eiffel> is the common parent of <eiffel>TIME_DURATION</eiffel>, <eiffel>DATE_DURATION</eiffel> and <eiffel>DATE_TIME_DURATION</eiffel>, it does not have many features available. Some features in class <eiffel>TIME</eiffel>, <eiffel>DATE</eiffel>, <eiffel>DATE_TIME</eiffel> return the same result and are more efficient to use. <eiffel>DURATION</eiffel> has to be use as the last solution.
|
||||
|
||||
====Comparison====
|
||||
|
||||
It includes intersection, inclusion and a special comparison.
|
||||
* <eiffel>is_equal</eiffel> is present and compare values, not references.
|
||||
* Feature <eiffel>intersects</eiffel> returns the mathematical result of the intersection of two intervals.
|
||||
* <eiffel>is_strict_included_by</eiffel>, <eiffel>strict_includes</eiffel>, <eiffel>is_included_by</eiffel> and <eiffel>includes</eiffel> are connected to the same notion of inclusion.
|
||||
* <, + > and >= use a special rule to compare intervals. int1 < int2 is true if int1 starts and ends strictly before int2. The other features use the <eiffel>same rule</eiffel> and<eiffel> is_equal</eiffel> if needed.
|
||||
* <eiffel>overlaps</eiffel> looks like <eiffel>intersects</eiffel> but the argument has to be after the current interval. <eiffel>is_overlapped</eiffel> is the opposite.
|
||||
* <eiffel>meets</eiffel> and <eiffel>is_met</eiffel> are used to test if two intervals have a common bound.
|
||||
|
||||
====Status Report====
|
||||
|
||||
The main part of the functions need an argument from the same generic type and return a <eiffel>BOOLEAN</eiffel> value.
|
||||
* <eiffel>empty</eiffel> tests if the bounds are equal.
|
||||
* <eiffel>has</eiffel>,<eiffel> strict_before</eiffel>, <eiffel>strict_after</eiffel>,<eiffel> before</eiffel> and <eiffel>after</eiffel> test the position of an element relatively to the current interval.
|
||||
|
||||
====Element change====
|
||||
|
||||
<eiffel>set_start_bound</eiffel> and <eiffel>set_end_bound</eiffel> are available to change the bounds.
|
||||
|
||||
====Operations====
|
||||
|
||||
<eiffel>Union</eiffel> and <eiffel>intersection</eiffel> are the mathematical functions. <eiffel>gather</eiffel> requires that two intervals meet each other and then yields the union.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
[[Property:title|More precision]]
|
||||
[[Property:weight|4]]
|
||||
<eiffel>TIME</eiffel> and <eiffel>TIME_DURATION</eiffel> are designed to deal with high precision in time. The only limit is the one from number representation.
|
||||
|
||||
The classes <eiffel>TIME</eiffel> and <eiffel>TIME_DURATION</eiffel> have an attribute <eiffel>fine_second</eiffel> (inherited from <eiffel>TIME_VALUE</eiffel>) which allows high precision. This attribute represents the number of seconds with fractions (it is an instance of <eiffel>DOUBLE</eiffel>). From this attribute are calculated second and fractional_second (which are functions): second is the truncated-to-integer part and fractional_second is the difference between the two previous one, so that the sum of second and fractional_second is always equal to fine_second (see invariant in <eiffel>TIME_VALUE</eiffel>).
|
||||
|
||||
As a result of this, when <eiffel>fine_second</eiffel> is positive (3.55 for example), <eiffel>second</eiffel> and <eiffel>fractional_second</eiffel> are also positive (3 and 0.55). When <eiffel>fine_second</eiffel> is negative (- 3.55 for example), <eiffel>second</eiffel> and <eiffel>fractional_second</eiffel> are also negative (- 3 and - 0.55).
|
||||
|
||||
Manipulation on second and fractional_second are in fact always made through fine_second. Users who do not want to deal with precision do not need to care about this.
|
||||
|
||||
Features dealing with <eiffel>fine_second</eiffel> and <eiffel>fractional_second</eiffel> are described here.
|
||||
|
||||
====Creation (common to <eiffel>TIME, </eiffel> <eiffel>TIME_DURATION</eiffel>)====
|
||||
* <eiffel>make_fine</eiffel> looks like make but it takes a <eiffel>DOUBLE </eiffel>for its third argument (instead of an <eiffel>INTEGER</eiffel>). fine_second is then set to this value.
|
||||
* <eiffel>make_by_fine_seconds</eiffel> looks like <eiffel>make_by_seconds</eiffel> but it takes a <eiffel>DOUBLE</eiffel> for argument (instead of an <eiffel>INTEGER</eiffel>). Comparison (common) There are no new features. The same ones are available since they are written to deal with precision. It is possible to compare two instances, one with precision and the other one without.
|
||||
|
||||
====Measurement and access====
|
||||
|
||||
In <eiffel>TIME</eiffel>:
|
||||
|
||||
- <eiffel>fine_seconds</eiffel> looks like seconds but it contains fractions.
|
||||
|
||||
In <eiffel>TIME_DURATION</eiffel>:
|
||||
|
||||
- <eiffel>fine_seconds_count</eiffel> looks like <eiffel>seconds_count</eiffel> but it contains fractions.
|
||||
|
||||
====Element change====
|
||||
* <eiffel>set_fine_second</eiffel> allows to set directly <eiffel>fine_second</eiffel> to a <eiffel>DOUBLE</eiffel>. In <eiffel>TIME</eiffel>, a precondition requires that the argument stands in the allowed range.
|
||||
* <eiffel>set_fractionals</eiffel> allows to set directly <eiffel>fractional_second</eiffel> to a <eiffel>DOUBLE</eiffel>. In <eiffel>TIME </eiffel>a precondition requires that the argument is positive and smaller than one. In <eiffel>TIME_DURATION</eiffel> the precondition is particular: it is not allowed to have an argument with a different sign than second. Otherwise, as long as <eiffel>fractional_second</eiffel> and <eiffel>second</eiffel> are linked to <eiffel>fine_second</eiffel>, such a setting would mean that second is also changed and <eiffel>fractional_second</eiffel> set to a different value. For example if <eiffel>fine_second</eiffel> = 4.5 (then second = 4 and fractional_second = 0.5) and - 0.8 is the argument of <eiffel>set_fractionals</eiffel>.
|
||||
|
||||
The result of that would be<eiffel> fine_second</eiffel> = 3.2 (then <eiffel>second</eiffel> = 3 and <eiffel>fractional_second</eiffel> = 0.2). It is better to prohibit that.
|
||||
|
||||
Comment: feature <eiffel>set_second</eiffel> (from both <eiffel>TIME</eiffel> and <eiffel>TIME_DURATION</eiffel>) will cut down <eiffel>fractional_second</eiffel> to zero.
|
||||
|
||||
====Operations====
|
||||
|
||||
- <eiffel>fine_second_add</eiffel> looks like <eiffel>second_add</eiffel> but takes a <eiffel>DOUBLE</eiffel> for argument.
|
||||
|
||||
In <eiffel>TIME_DURATION</eiffel>:
|
||||
|
||||
- <eiffel>canonical</eiffel> and <eiffel>to_canonical</eiffel> deals already with precision. There is nothing different.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
[[Property:title|EiffelTime Library]]
|
||||
[[Property:link_title|EiffelTime]]
|
||||
[[Property:weight|9]]
|
||||
Type: Library <br/>
|
||||
Platform: Any <br/>
|
||||
|
||||
|
||||
See:
|
||||
* [[EiffelTime|Content]]
|
||||
* [[ref:libraries/time/reference/index|Reference]]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user