Timepattern misbehavior with 24H times before 10 am?
Richard Blatchly
rblatchly at keene.edu
Wed Jul 30 19:30:23 PDT 2008
Jim:
Thanks for getting back to me. I was trying to be careful not to
call it a bug--perhaps a matter of taste? And, as I said, once I saw
it, it is very easy to fix.
The "iCal" format is the file that can be imported into Apple's
iCal. According to Wikipedia, it is more formally known as RFC 2445,
and has the isc extension. It's pretty simple, but very fussy about
the formats. In particular, the date/time format uses 8 text digits
for the date (yyyymmdd), then a "T", then 6 text digits for the time
(hhmmss). If you feed it 5 text digits for the time, it gets very
grumpy.
The nitty-gritty of the file formats are at http://tools.ietf.org/
html/rfc2445 .
It's pretty straightforward to write these files. It took me less
than an hour to write the following (yes, I know I could have entered
all of my data in less time, and Dave T could have coded this in 10
minutes. But now it's automated, dammit!). I have tried to comment
on the more obscure parts. Also, I have some extra functionality in
here because the schedule people I send this to need the weekdays as
M T W R F, while the ics file needs the days to look like Mo Tu We Th
Fr. I used two arrays to translate. I have used only a fraction of
the options available, because I was looking for simple schedule info
I could share with a broadcast calendar, or using Google Calendar.
If this gets mangled due to line wraps, I can post it as a text file
elsewhere.
Enjoy!
Rich Blatchly
____
local lvCalendarStuff, lvCourseDays, DayLoopCounter,
DayConverterTable1, DayConverterTable2, lvCourseStartDate
fileglobal SemesterStartDate, SemesterEndDate
;database fields used in this file: Text fields: Days,
StartTime, EndTime, Instructor, Room. Integer fields: Number and
LectSection
SemesterStartDate="20080825"
SemesterEndDate="20081205T180000"
lvCourseStartDate=SemesterStartDate
;Days in my file are in single letters, while ics requires two
letter days. These two tables allow conversion. The one and two
letter versions have days in the same position.
DayConverterTable1 = "M,T,W,R,F"
DayConverterTable2 = "MO,TU,WE,TH,FR"
;Calendars begin with this text
lvCalendarStuff = "BEGIN:VCALENDAR"+¶+"VERSION:2.0"+¶
FirstRecord
Loop
;events are wrapped between a begin line and an end line
lvCalendarStuff=lvCalendarStuff+"BEGIN:VEVENT"+¶
;The start and end date are the same day for an event
shorter than one day. They are formatted with the date first, the
"T", then the time. Put a "z" after the time if you want it to be
universal (I don't).
lvCourseStartDate=pattern(val(SemesterStartDate)+arraysearch
(DayConverterTable1,Days[1,1],1,",")-1,"#")
lvCalendarStuff=lvCalendarStuff+"DTSTART:"+lvCourseStartDate
+"T"+?(length(timepattern(time(StartTime),"HHMMSS"))
<6,"0"+timepattern(time(StartTime),"HHMMSS"),timepattern(time
(StartTime),"HHMMSS"))+¶
lvCalendarStuff=lvCalendarStuff+"DTEND:"+lvCourseStartDate+"T"+?
(length(timepattern(time(EndTime),"HHMMSS")) <6,"0"+timepattern(time
(EndTime),"HHMMSS"),timepattern(time(EndTime),"HHMMSS"))+¶
;Summary is used as the title of the event.
lvCalendarStuff=lvCalendarStuff+"SUMMARY:"+pattern(Number,"#")
+"-"+pattern(LectSection,"##")+¶
lvCalendarStuff=lvCalendarStuff+"DESCRIPTION:"+Instructor
+"/"+Room+¶
DayLoopCounter = 1
lvCourseDays=""
loop
lvCourseDays=lvCourseDays+array
(DayConverterTable2,arraysearch(DayConverterTable1,Days
[DayLoopCounter,DayLoopCounter],1,","),",")+","
DayLoopCounter=DayLoopCounter+1
until DayLoopCounter = 4
;The arraystrip gets rid of empty elements for those
schedules that have fewer than 3 days. This avoids having a
complicated conditional in the loop.
arraystrip lvCourseDays,","
;These schedules repeat weekly until the end of the
semester. At some point, I'll make the dates permanent and
accessable through a form.
lvCalendarStuff=lvCalendarStuff
+"RRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL="+SemesterEndDate
+";BYDAY="+lvCourseDays+";WKST=SU"+¶
lvCalendarStuff=lvCalendarStuff+"END:VEVENT"+¶
downrecord
Until info("Stopped")
lvCalendarStuff=lvCalendarStuff+"END:VCALENDAR"
;Sloppy, I know, but I don't care if the old schedule file gets
overwritten every time. Someday, maybe I will and will use the file
name utilities.
FileSave info
("DesktopFolder") ,"ScheduleCalendar.ics","",lvCalendarStuff
;end of procedure----------------------------
Jim Rea said:
> I don't think this is a bug. This function doesn't claim to be in
> "isc"
> format, in fact, I have no idea what this is. Since this format could
> also be used for elapsed time, I think it is just fine that there
> is no
> leading zero (for example if someone runs a race in 90 minutes I don't
> think you want the display to read 01:30, rather, you would want just
> 1:30).
More information about the Qna
mailing list