galaxy.lang
Class DateUtil

java.lang.Object
  |
  +--galaxy.lang.DateUtil

public class DateUtil
extends java.lang.Object

This class encapsulates a set of static functions for manipulating dates and semantic frames.

See Also:
Predicate

Field Summary
static int defaultYear
          The current year. For example: 1998.
 
Method Summary
static boolean after(GFrame dfr1, GFrame dfr2)
          Return true if the first date frame is after the second date frame.
static boolean before(GFrame dfr1, GFrame dfr2)
          Return true if the first date frame is before the second date frame.
static boolean equals(GFrame dfr1, GFrame dfr2)
          Return true if the first date frame is the same as the second date frame.
static void insertDate(GFrame frame, java.util.Calendar cal)
          Parse dateString and insert the appropriate predicates into the frame representing that date and time.
static void main(java.lang.String[] args)
          For testing only.
static Predicate makeDateFrame(GFrame fr)
          Construct a date frame from the frame that tina generates.
static boolean monthEquals(GFrame dfr, GFrame mfr)
          Return true if the month in both frames is non-null and the same value.
static Predicate parseDate(java.lang.String str)
          Parse a date string and produce the corresponding GFrame.
static GVector prepareDates(GFrame tinaFrame, boolean silent)
          Generate a GVector of date frames from a tina frame.
static void prepareTimesForSQL(GFrame f, int zoneOffset)
          Locate time predicates, and convert them from relative time to absolute time useful for sql queries.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultYear

public static final int defaultYear
The current year. For example: 1998.
Method Detail

prepareTimesForSQL

public static void prepareTimesForSQL(GFrame f,
                                      int zoneOffset)
                               throws TimeRangeMakerException
Locate time predicates, and convert them from relative time to absolute time useful for sql queries. Absolute times are represented by absolute_tod (absolute time of day) qsets. If a time range is needed, absolute_start_time and absolute_end_time predicates are used with absolute_tod topics. If a point in time is needed, it is represented by a absolute_time predicate.

Predicates which are converted are: start_time, end_time, before, after, at and time_interval.

For example, assume today is Friday May 15, 1998

/
:pred {p month_date
          :topic {q date
                :day "saturday"
                :exists 1 } }
:pred {p absolute_start_time
      :topic {q absolute_tod
              :year 1998
              :month "may"
              :dom 16
              :hour 0
              :minute 0 } }
:pred {p absolute_end_time
      :topic {q absolute_tod
              :year 1998
              :month "may"
              :dom 16
              :hour 23
              :minute 59 } }
:pred {p month_date
      :topic {q date
                 :day "weekend"
                 :exists 1 }  } }
:pred {p absolute_start_time
      :topic {q absolute_tod
              :year 1998
              :month "may"
              :dom 16
              :hour 0
              :minute 0 } }
:pred {p absolute_end_time
      :topic {q absolute_tod
              :year 1998
              :month "may"
              :dom 17
              :hour 23
              :minute 59 } }
saturday 3:00 pm
:pred {p absolute_time
      :topic {q absolute_tod
              :year 1998
              :month "may"
              :dom 16
              :hour 3
              :minute 0 } }

This is a grammar of time predicates we handle as input.

   <tina_time>       :=<time_preds>
                      |<time_relation>
                      |<time_preds> <time_relation>
   <time_relation> := <start_end> | <after> | <before> | <at>
   <start_end> :=                         ;;Generated when the user says "between".
              :pred {p start_time         ;;Inclusive
                  <complex_time>}
              :pred {p end_time
                  <complex_time>}
   <after> := :pred {p after              ;;Exclusive
                  <complex_time>}
   <before> := :pred {p before            ;;Exclusive
                  <complex_time>}
   <at> := :pred {p at
                  :topic <time>}
   <complex_time> :=
      [(<at> | :topic <time>)]
      [(<month_date> | :topic <date>)]
      [(<time_interval> | :topic <time_of_day>)]
   <time_preds> := <month_date> <time_interval> <at>   ;; One or more of these.
   <month_date> := :pred {p month_date
                              :topic  <date> }
   <date> := {q date
                  :day <dow> }
   <time_interval> := :pred {p time_interval
                              :topic {q time_of_day
                                          :name <interval> } }
   <time> = {q time
              <hour>
              :minutes #
              [:xm "a m"]}
   <hour> := :hour # | :military #
   <interval> := "morning" | "night" | "afternoon" | "evening"
   <dow> := "weekend" | "monday" | "tuesday" | "wednesday" | "thursday" | ...

prepareDates

public static GVector prepareDates(GFrame tinaFrame,
                                   boolean silent)
Generate a GVector of date frames from a tina frame. If the tina frame does not contain a month_date predicate, null is returned. It's a GVector, not a single value because of cases like weekend that can return multiple dates. If the tina frame designates a specific date, then the following fields are created in the Date frame.

year The full year.
month The number of the month. 1 == January
day Day of the month.
wday Day of the week. 1 == Sunday.
yday Day of the year.

If the tina frame designates a day of the week, then wday field is added designating the day of the week as an integer. The name of the day is carried over. Note a name for the day of the week is not generated if the date is given as month, day. Presumably this is for language generation reasons. Answer in the manner the question was asked.

Tina frameDate frame
{p date :day "saturday"}
({p date :wday 7 :day_name "saturday"})
{p date :name "today"}
 ({p date
     :year 1998
     :name "today"
     :wday 3
     :yday 153
     :day 2
     :month 6})
{p date :name "weekend"}
 ({p date
     :wday 7
     :day_name "saturday"}
  {p date
     :wday 1
     :day_name "sunday"} )
{p date :month "may" :day_number 15}
 ({p date
    :year 1998
    :wday 6
    :yday 135
    :day 15
    :month 5})
 

Parameters:
tinaFrame - The tina frame
silent - If true insert :silent 1 in to the frame. Otherwise remove :silent
Returns:
A GVector of date frames.

parseDate

public static Predicate parseDate(java.lang.String str)
Parse a date string and produce the corresponding GFrame. A Predicate with the name "date" will be returned. The following fields will be set if the corresponding value was in the input string.
:year
:month
:day
:wday

The date string can contain a month name, day of the week name, and/or an integer. If the integer is less than 32, it is considered the day of the month. If it is less than 100 it is considered the last two digits of the year. Otherwise it is considered the year.

See Also:
Predicate

monthEquals

public static boolean monthEquals(GFrame dfr,
                                  GFrame mfr)
Return true if the month in both frames is non-null and the same value.

before

public static boolean before(GFrame dfr1,
                             GFrame dfr2)
Return true if the first date frame is before the second date frame.

after

public static boolean after(GFrame dfr1,
                            GFrame dfr2)
Return true if the first date frame is after the second date frame.

equals

public static boolean equals(GFrame dfr1,
                             GFrame dfr2)
Return true if the first date frame is the same as the second date frame.

makeDateFrame

public static Predicate makeDateFrame(GFrame fr)
Construct a date frame from the frame that tina generates.
Here are the cases handled.

main

public static void main(java.lang.String[] args)
For testing only.

insertDate

public static void insertDate(GFrame frame,
                              java.util.Calendar cal)
                       throws java.text.ParseException
Parse dateString and insert the appropriate predicates into the frame representing that date and time. An attempt is made to relativize the. We check for yesterday, today tomorrow, and then names of days of the week for the following six days. Otherwise we just express the date directly. 12:00 is converted to noon, 0:00 to midnight. This method is useful when a date retrieved from the database needs to be expressed to the user.