# $Id: timeLookup.n3,v 1.1 2004/04/14 22:53:07 connolly Exp $
# see changelog at end

# example:
# http://www.timeanddate.com/worldclock/fixedtime.html?day=20&month=4&year=2004&hour=12&min=24&sec=0&p1=64

# cwm's time:format follows python's strftime, which see
# http://www.python.org/doc/current/lib/module-time.html

@prefix cal: <http://www.w3.org/2002/12/cal/ical#> .
@prefix k: <http://opencyc.sourceforge.net/daml/cyc.daml#> .
@prefix map: <http://www.w3.org/2000/10/swap/pim/earthMap#>.
@prefix str: <http://www.w3.org/2000/10/swap/string#>.
@prefix time: <http://www.w3.org/2000/10/swap/time#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix dt: <http://www.w3.org/2001/XMLSchema#>.

@prefix : <timeLookup#>.


# In the America/Chicago timezone, there's a city called Chicago.
{
  ?TZ a cal:Vtimezone;
    log:uri ?TZI.
  (?TZI "cal/tzd/[^/]+/([^#]+)#") str:scrape ?CITYNAME
} => { [ map:cityName ?CITYNAME ] k:inRegion ?TZ }.


# patch
{ ?WHERE map:cityName "New_York" } => { ?WHERE map:cityName "New York" }.

# map city names to timeanddate.com codes
#<option value="5">Adelaide
{
  ?WHERE map:cityName ?CITYNAME.
  <http://www.timeanddate.com/worldclock/fixedform.html> log:content ?TXT.
  ("<option value=\"(\\d+)\">" ?CITYNAME) str:concatenation ?PAT.
  (?TXT ?PAT) str:scrape ?CODE.
}
 => { ?WHERE :placeCode ?CODE }.


{
  ?TZ a cal:Vtimezone.
  [] :placeCode ?CODE; k:inRegion ?TZ.
  ?WHEN ?TZ ?DATESTR.

  ?PG log:uri [
    is str:concatenation of (
      [ is time:format of
        ([ is str:concatenation of (?DATESTR "Z")]
         "http://www.timeanddate.com/worldclock/fixedtime.html?day=%d&month=%m&year=%Y&hour=%H&min=%M&sec=%S")
      ]
      "&p1="
      ?CODE ) ].
} => {
  ?WHEN :timePage ?PG
}.


# Current <b>UTC</b> (or GMT)-time used: <b>Tuesday, April 20, 2004, at 17:25:00</b>
{ ?WHEN :timePage ?PG.
  ?PG log:content ?TXT.
  (?TXT "time used: <b>([^<]+)</b>") str:scrape ?ZTIME_FRIENDLY.
}
 => { ?WHEN :zTimeFriendly ?ZTIME_FRIENDLY }.

{
  ?WHEN :zTimeFriendly ?ZTIME_FRIENDLY.
  (?ZTIME_FRIENDLY "\\w+, (\\w+) ") str:scrape ?MONTHNAME.
  (?ZTIME_FRIENDLY "\\w+, \\w+ (\\d+),") str:scrape ?DD.
  (?ZTIME_FRIENDLY "\\w+, \\w+ \\d+, (\\d+),") str:scrape ?YYYY.
  (?ZTIME_FRIENDLY "\\w+, \\w+ \\d+, \\d+, at (.*)") str:scrape ?HH_MM_SS.
  [] :monthName ?MONTHNAME; :index ?MM.
  (?YYYY "-" ?MM "-" ?DD "T" ?HH_MM_SS "Z") str:concatenation ?ZTIME.
}
 => { ?WHEN dt:dateTime ?ZTIME }.


# ugh...
k:January   :monthName "January";    :index "01".
k:February  :monthName "February";   :index "02".
k:March     :monthName "March";      :index "03".
k:April     :monthName "April";      :index "04".
k:May       :monthName "May";        :index "05".
k:June      :monthName "June";       :index "06".
k:July      :monthName "July";       :index "07".
k:August    :monthName "August";     :index "08".
k:September :monthName "September";  :index "09".
k:October   :monthName "October";    :index "10".
k:November  :monthName "November";   :index "11".
k:December  :monthName "December";   :index "12".




# $Log: timeLookup.n3,v $
# Revision 1.1  2004/04/14 22:53:07  connolly
# localtime to ztime conversion via timeanddate.com seems to work!
#
