<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>PROBLEMS OF DATE AND TIME DATA TYPES IN RELATIONAL MODEL OF DATA</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Dimitrov V.</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>University of Sofia</institution>
          ,
          <addr-line>Sofia</addr-line>
          ,
          <country country="BG">Bulgaria</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2018</year>
      </pub-date>
      <fpage>307</fpage>
      <lpage>312</lpage>
      <abstract>
        <p>Several years after the initial announcement of the relational model of data, Codd published a review on the model, so called Version 2. This review is based on the experience of relational database systems implementation in the intermediate period. One of the main corrections are recommendation on date and time data types. This paper reinvestigate the topic from the nowadays point of view.</p>
      </abstract>
      <kwd-group>
        <kwd>date</kwd>
        <kwd>time</kwd>
        <kwd>relational model of data</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <sec id="sec-1-1">
        <title>Every computer system is a hierarchy of virtual machines: hardware, BIOS, operating system,</title>
        <p>system software (programming languages, database systems, run-times), middleware, application.</p>
      </sec>
      <sec id="sec-1-2">
        <title>Every such a “virtual machine” uses its own system clock and date-time representation. Usually,</title>
        <p>system clocks and date-time representations are incompatible with each other that is a stable source for
vulnerabilities. The most popular among these vulnerabilities is Year 2000 problem.</p>
      </sec>
      <sec id="sec-1-3">
        <title>The system clock’s time scale begins from some fixed time point called “epoch start” and ends</title>
        <p>in another time point – “epoch end”. The time scale is discrete based on some fixed tick, like seconds,
milliseconds etc. The time points are measured in the number of ticks since the epoch start.</p>
      </sec>
      <sec id="sec-1-4">
        <title>For example, UNIX and Posix system’s epoch begins at 1970-01-01T00:00:0Z, the tick is one</title>
        <p>second. Date-time is stored in 32-bits or 64-bits signed integer. This means that for 32-bits systems,
epoch ends at 2038-01-19T03:14:07Z, or in other words it is Year 2038 problem.</p>
      </sec>
      <sec id="sec-1-5">
        <title>Microsoft supports several epochs for their offerings, but the tick is 100 nanoseconds.</title>
      </sec>
      <sec id="sec-1-6">
        <title>Datetime functions convert time points into calendar dates and times using information about leap seconds, time zones, daylight saving times etc.</title>
      </sec>
      <sec id="sec-1-7">
        <title>In the initial representation of the relational model of data [1], Codd introduced the domains as</title>
        <p>sets of atomic data. Date and time data types are very important business data, and in the next version
of the model, so called RMD-2 (Relational Model of Data – Version 2) [2], he defined four classes
date and time data types (RT-4 – RT-7). There are 14 specific recommendation for dates listed in
RT</p>
      </sec>
      <sec id="sec-1-8">
        <title>4, and 12 for times in RT-7.</title>
      </sec>
      <sec id="sec-1-9">
        <title>Initial implementations did not pay much attention on dates and times. Usually, they were</title>
        <p>local dates and times, based on the operating system clock or the programming language’s system
clock used for DBMS implementation. The next generations of DBMS’s have more sophisticated
dates and times with time zones etc., but continue to support compatibility with these early date and
time data types.</p>
      </sec>
      <sec id="sec-1-10">
        <title>ISO tries to put some order introducing standards for date and time formats for data</title>
        <p>interchange [3] and for SQL [4]. These standards fix the current state of the art introducing more
features as “interchanging parts agreements” or “implementer’s option”.</p>
      </sec>
      <sec id="sec-1-11">
        <title>The aim of this paper is to give a clear vision on date and time data types in the relational model of data without any compatibility considerations. For that purpose, Codd’s recommendations are the base.</title>
        <p>2. RT-4 Calendar Dates &amp; RT-5 Clock Times &amp; RT-6 Coupling of Dates
with Times &amp; RT-7 Time-zone Conversion</p>
        <sec id="sec-1-11-1">
          <title>RT-4: From the user's standpoint, dates appear to be treated by the DBMS as if they were atomic values. However, the DBMS supports functions that are capable of treating as separate components the year, month, and day of the month.</title>
        </sec>
        <sec id="sec-1-11-2">
          <title>RT-5: From the user's standpoint, clock times appear to be treated by the DBMS as if they were atomic values. The DBMS however, supports functions that are capable of treating as separate components the hours, minutes of the hour, and seconds of the minute. The services provided include counterparts to the first 12 of the 14 services listed in the discussion of RT-4.</title>
        </sec>
        <sec id="sec-1-11-3">
          <title>RT-6: The DBMS supports a composite data type consisting of the data type DATE coupled with the data type TIME, allowing the functions applicable to dates alone or times alone to be applied to combinations in which DATE plays the role of the high-order part and TIME the low-order part.</title>
        </sec>
        <sec id="sec-1-11-4">
          <title>RT-7: The DBMS supports (1) the conversion of every date-time pair from any specified time zone to Greenwich date and Greenwich mean time, and (2) the inverse conversion of Greenwich datetime pairs back into a specified time zone.</title>
        </sec>
      </sec>
      <sec id="sec-1-12">
        <title>The services provided by Feature RT-4 include the 14 that follow:</title>
        <p>1.</p>
        <sec id="sec-1-12-1">
          <title>Independence of date and time from particular time zones in which users are located, by use of Greenwich dates and Greenwich mean time</title>
        </sec>
      </sec>
      <sec id="sec-1-13">
        <title>Codd recommends database system to store dates and times in the database only as UTC. This means that there is no need to store time zones for every date or time entry.</title>
      </sec>
      <sec id="sec-1-14">
        <title>This recommendation, especially in the current situation of business globalization, is very reasonable – space for and processing of time zones would be saved. In the worst case, processing of time zones is nearly the same as conversion to the local time zone date and time.</title>
      </sec>
      <sec id="sec-1-15">
        <title>In the context of this recommendation, the database system clock’s epoch can be that of</title>
      </sec>
      <sec id="sec-1-16">
        <title>ISO/DIS 8601:2018 – proleptic Gregorian calendar with year zero (leap year), with negative dates before the epoch beginning.</title>
      </sec>
      <sec id="sec-1-17">
        <title>For all other calendars, like Julian, Indian, Islamic, Jew’s etc., suitable conversations can be implemented.</title>
        <p>2.</p>
        <sec id="sec-1-17-1">
          <title>The function called NOW yields for any site the current date and time that are in effect in the time zone of the site.</title>
        </sec>
      </sec>
      <sec id="sec-1-18">
        <title>The function NOW is very simple at first glance, but its implementation has many variations in the currently available database systems. The term “local time” may be the local time of the site from which the session has been initiated, but what if the user cross time zone during the session, for example if he/she is traveling in a plane, train or car?</title>
      </sec>
      <sec id="sec-1-19">
        <title>Another interpretation of the term local time is the database site local time, but if the database is distributed on several time zones, or the DBMS run on a cloud spread on several time zones?</title>
      </sec>
      <sec id="sec-1-20">
        <title>The general solution is simply to fix local time zone in some global parameters of the DBMS.</title>
        <p>3.</p>
        <sec id="sec-1-20-1">
          <title>Extraction of any one or any pair of the three components, a form of truncation.</title>
        </sec>
      </sec>
      <sec id="sec-1-21">
        <title>Component extraction from dates and times is reasonable to be done only for single component, but not for pairs, triples etc., because some kind of pairs have no reason, like the pair year and day of the month.</title>
      </sec>
      <sec id="sec-1-22">
        <title>There are very many combinations for datetime, but only few of them are usable.</title>
      </sec>
      <sec id="sec-1-23">
        <title>If the user can extract single component, he/she can combine single components in a way that he/she needs.</title>
      </sec>
      <sec id="sec-1-24">
        <title>Implementation of component extraction must be at data manipulation language’s level. At implementation level, this is usually an embedded feature in the programing language if the dates and times are stored as structures for year, month, day, hour, minute and second.</title>
      </sec>
      <sec id="sec-1-25">
        <title>Another possibility is dates and times are stored as ticks passed from the beginning of the epoch. In that case sophisticated conversation from ticks to calendar dates and vice versa must be implemented.</title>
      </sec>
      <sec id="sec-1-26">
        <title>Usually, database systems store dates and times as string of components.</title>
        <sec id="sec-1-26-1">
          <title>Extraction with rounding of either year alone or year followed by month. 4. 5.</title>
        </sec>
      </sec>
      <sec id="sec-1-27">
        <title>Extraction with rounding to some finer component is not very useful functionality.</title>
      </sec>
      <sec id="sec-1-28">
        <title>For ISO/DIS 8601:2018 this recommendation can make sense especially for the date and time formats where the finer component is represented with decimal fraction. For example, the component day, if it is the finest component, may contain decimal point and fraction for hour, minute, and second.</title>
        <sec id="sec-1-28-1">
          <title>Conversion of the combination year, month, day of the month to the year followed by day of the year, as well as conversion in the opposite direction.</title>
          <p>There are many more formats of the kind year – day of the year, such like:
but also:
year – hour of the year;
year – minute of the year;
year – second of the year,
year, month – hour of the month;
year, month – second of the month;
year – day of the year – hour of the day;
year – day of the year – second of the day;
year – hour of the year, second.</p>
        </sec>
      </sec>
      <sec id="sec-1-29">
        <title>In addition, ISO/DIS 8601:2018 has a format for dates: year – week of the year – day of the week. If this format of the date in combine with the time, many more formats would be generated.</title>
      </sec>
      <sec id="sec-1-30">
        <title>It is clear that a few of these formats are useful, but many more are not. So, must be decided which formats to implement and which ones – not.</title>
      </sec>
      <sec id="sec-1-31">
        <title>The best solution is if the data manipulation language is open to new data types. In that case, the user can create the date and time type he/she needs. Some basic functionality must be implemented like conversion of datetime to year – day of the year, hour, minute, second; to year – minute of the year, second; to year – second of the year etc.</title>
      </sec>
      <sec id="sec-1-32">
        <title>If the date format year – week of the year – day of the week is supported, at least conversion to year, month, and day format must exists.</title>
      </sec>
      <sec id="sec-1-33">
        <title>For conversions with the time, date component must be available, because there are no other way to have information about the leap seconds.</title>
        <p>6.</p>
        <sec id="sec-1-33-1">
          <title>Computation of the difference between two dates of similar or distinct external types, where each argument is expressed as a. years only, or b. years and months, or</title>
          <p>c. years, months, and days of the month, or
d. years, and days of the year.</p>
        </sec>
        <sec id="sec-1-33-2">
          <title>These four options must be available to users, and the result must be of the same external type as the argument that is coarser.</title>
        </sec>
      </sec>
      <sec id="sec-1-34">
        <title>The interval between two dates must be in nominal units, because the nominal units are practically used.</title>
      </sec>
      <sec id="sec-1-35">
        <title>What exactly are nominal units? For example, nominal month lasts from a day in the current month until the beginning of the same day in the next month. If such a day in the next month does not exist then the end of the next month is used for such purpose. This rule applies to all other nominal units like year, day, hour and minute.</title>
      </sec>
      <sec id="sec-1-36">
        <title>ISO/DIS 8601:2018 suggests this rule for nominal units, but it is not obligatory rule for the interchanging parties. Even more, the standard suppose that the difference between two date (datetimes or times) can be negative.</title>
      </sec>
      <sec id="sec-1-37">
        <title>The idea behind the interval is that when to the earlier date the interval is added the result would be the second date. In that case, rounding and truncates to the result are not acceptable. The user can extract from the interval its nominal components. 310</title>
        <sec id="sec-1-37-1">
          <title>Conversion of date intervals into years only or months only or days only, using truncation or rounding as specified, if the conversion is from fine units to coarser units.</title>
        </sec>
      </sec>
      <sec id="sec-1-38">
        <title>The user can extract interval components and if he/she want to round them. This must not be a part of the DMBS implementation.</title>
        <sec id="sec-1-38-1">
          <title>Arithmetic on dates, including computation of a date from a given date plus or minus a date interval, without the adoption of dates and date intervals as distinct data types.</title>
        </sec>
      </sec>
      <sec id="sec-1-39">
        <title>Intervals are composed of nominal components. This means that it is possible day and month components in the interval to have zero value, but this is impossible for them in a date. Therefore, the dates cannot be intervals. That is why the database systems implement intervals as different data type from the dates.</title>
      </sec>
      <sec id="sec-1-40">
        <title>Allowed arithmetic with dates (datetimes) and intervals is:</title>
      </sec>
      <sec id="sec-1-41">
        <title>Arithmetic with only times is not well defined.</title>
      </sec>
      <sec id="sec-1-42">
        <title>Comparison supposes that some ordering exists in the domain.</title>
        <p>10.</p>
        <sec id="sec-1-42-1">
          <title>Finding the most recent date of a collection.</title>
          <p>difference of two dates (datetimes) gives an interval;
to a date (datetime) an interval can be added and the result is another valid date;
from a date (datetime) an interval can be subtracted and the result is another valid
date.</p>
        </sec>
        <sec id="sec-1-42-2">
          <title>Pairwise comparison of dates, including testing of pairs of dates to see which is the more recent and which is the less recent.</title>
        </sec>
      </sec>
      <sec id="sec-1-43">
        <title>The key term, here, is the “collection”. In the context of relational model of data, collection of data must be a set of values from the same domain or base type. Here, base types are date, time and datetime. All other external dates and times are domains (in SQL distinct types) based on them.</title>
      </sec>
      <sec id="sec-1-44">
        <title>Here, the above considerations are applied.</title>
        <sec id="sec-1-44-1">
          <title>Finding the least recent date of a collection.</title>
        </sec>
        <sec id="sec-1-44-2">
          <title>All varieties of joins based on comparing dates.</title>
        </sec>
      </sec>
      <sec id="sec-1-45">
        <title>In RMD-2, joins require both columns to be from the same domain or base type. In this case, domains are based on the base types date, time and datetime. Therefore, both column must have as base type date, time or datetime.</title>
        <sec id="sec-1-45-1">
          <title>The ability to report dates in at least one of the following formats:</title>
          <p>a. European format: D,M,Y;
b. North American format: M,D,Y;
c. computer format: Y,M,D;
d. in the Indian calendar with lunar months.</p>
        </sec>
      </sec>
      <sec id="sec-1-46">
        <title>Most of currently available database systems support this recommendation. The problem is with some exotic and rare calendars.</title>
        <p>14.</p>
        <sec id="sec-1-46-1">
          <title>Two types of date-conversion functions:</title>
          <p>a. DATE_IN for transforming dates from external representation of dates to the internal
representation;
b. DATE_OUT for transforming dates in the reverse direction, with the DBA having the
option of putting into effect functions defined and specified by the DBA either for all
users of a given DBMS or for specified classes of users (instead of or in addition to
those supplied by the DBMS vendor).</p>
        </sec>
      </sec>
      <sec id="sec-1-47">
        <title>This option is needed because users with different responsibilities and those located in different countries (even within a single country) may employ different kinds of dates externally with respect to the DBMS.</title>
      </sec>
      <sec id="sec-1-48">
        <title>These two date conversion functions stay aside from all other considerations. The data manipulation language has reach set of data types for dates and times. The DBMS implements date, time and datetime. Conversion of external data types to internal ones is a problem of the language translator (interpreter) but not a user or implementation problem.</title>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>4. Conclusion</title>
      <sec id="sec-2-1">
        <title>Recommendations listed here with the comments on them can be used as methodology for</title>
        <p>dates and times. Some of above-mentioned functionalities are implemented in the currently available
database systems. Other functionalities can be implemented in SQL. There are no need to wait for a</p>
      </sec>
      <sec id="sec-2-2">
        <title>DBMS that totally supports date and time recommendations.</title>
      </sec>
      <sec id="sec-2-3">
        <title>Even, it is possible to implement all above recommendations with different date and time</title>
        <p>representations from the DBMS native one.</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Acknowledgements References</title>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          <article-title>This work is supported by the project</article-title>
          <source>ДН 02/9/17.12</source>
          .
          <article-title>2016 of the Bulgarian Science fund</article-title>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>