Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
LOCAL loOutlook, loNamespace, loFolder, loItems, ldDate
ldDate = DATE() && Example date
* Create Outlook application object
loOutlook = CREATEOBJECT("Outlook.Application")
loNamespace = loOutlook.GetNameSpace("MAPI")
* Access the Calendar folder (default calendar)
loFolder = loNamespace.GetDefaultFolder(9) && 9 corresponds to olFolderCalendar
loItems = loFolder.Items
* Now you would filter or iterate through loItems to find if there's a holiday
* This part of the logic needs to be developed based on your criteria for identifying holidays
RELEASE loOutlook
So that's speaking of a separate holidays calendar again.MS said:If you have a work or school account in Microsoft 365, you can subscribe to a holidays calendar using Outlook on the web and receive automatic updates when holidays are added or changed.
LPARAMETERS dtdate
LOCAL liMonth, liYear, liCount, liDay
liMonth = MONTH(dtdate)
liYear = YEAR(dtdate)
DO CASE
CASE liMonth = 1
IF TTOD(dtdate) = DATE(liYear, liMonth, 1)
This.DateHeaderText = "New Years Day"
ENDIF
IF DOW(DATE(liYear, liMonth, 1)) = 1 AND (DATE(liYear, liMonth, 1) + 1 = TTOD(dtdate))
This.DateHeaderText = "New Years Day (Observed)"
ENDIF
liCount = 0
FOR liDay = 1 TO 31
IF DOW(DATE(liYear, liMonth, liDay)) = 2
liCount = liCount + 1
IF liCount = 3
EXIT
ENDIF
ENDIF
ENDFOR
IF TTOD(dtdate) = DATE(liYear, liMonth, liDay)
This.DateHeaderText = "Martin Luther King Day"
ENDIF
CASE liMonth = 2
liCount = 0
FOR liDay = 1 TO 28
IF DOW(DATE(liYear, liMonth, liDay)) = 2
liCount = liCount + 1
IF liCount = 3
EXIT
ENDIF
ENDIF
ENDFOR
IF TTOD(dtdate) = DATE(liYear, liMonth, liDay)
This.DateHeaderText = "Presidents Day"
ENDIF
CASE liMonth = 5
FOR liDay = 31 TO 1 STEP -1
IF DOW(DATE(liYear, liMonth, liDay)) = 2
EXIT
ENDIF
ENDFOR
IF TTOD(dtdate) = DATE(liYear, liMonth, liDay)
This.DateHeaderText = "Memorial Day"
ENDIF
CASE liMonth = 6
IF TTOD(dtdate) = DATE(liYear, liMonth, 19)
This.DateHeaderText = "Juneteenth"
ENDIF
DO CASE
CASE DOW(DATE(liYear, liMonth, 19)) = 7 AND (DATE(liYear, liMonth, 19) - 1 = TTOD(dtdate))
This.DateHeaderText = "Juneteenth (Observed)"
CASE DOW(DATE(liYear, liMonth, 19)) = 1 AND (DATE(liYear, liMonth, 19) + 1 = TTOD(dtdate))
This.DateHeaderText = "Juneteenth (Observed)"
ENDCASE
CASE liMonth = 7
IF TTOD(dtdate) = DATE(liYear, liMonth, 4)
This.DateHeaderText = "Independence Day"
ENDIF
DO CASE
CASE DOW(DATE(liYear, liMonth, 4)) = 7 AND (DATE(liYear, liMonth, 4) - 1 = TTOD(dtdate))
This.DateHeaderText = "Independence Day (Observed)"
CASE DOW(DATE(liYear, liMonth, 4)) = 1 AND (DATE(liYear, liMonth, 4) + 1 = TTOD(dtdate))
This.DateHeaderText = "Independence Day (Observed)"
ENDCASE
CASE liMonth = 9
FOR liDay = 1 TO 30
IF DOW(DATE(liYear, liMonth, liDay)) = 2
EXIT
ENDIF
ENDFOR
IF TTOD(dtdate) = DATE(liYear, liMonth, liDay)
This.DateHeaderText = "Labor Day"
ENDIF
CASE liMonth = 10
liCount = 0
FOR liDay = 1 TO 31
IF DOW(DATE(liYear, liMonth, liDay)) = 2
liCount = liCount + 1
IF liCount = 2
EXIT
ENDIF
ENDIF
ENDFOR
IF TTOD(dtdate) = DATE(liYear, liMonth, liDay)
This.DateHeaderText = "Columbus Day"
ENDIF
CASE liMonth = 11
IF TTOD(dtdate) = DATE(liYear, liMonth, 11)
This.DateHeaderText = "Veterans Day"
ENDIF
DO CASE
CASE DOW(DATE(liYear, liMonth, 11)) = 7 AND (DATE(liYear, liMonth, 11) - 1 = TTOD(dtdate))
This.DateHeaderText = "Veterans Day (Observed)"
CASE DOW(DATE(liYear, liMonth, 11)) = 1 AND (DATE(liYear, liMonth, 11) + 1 = TTOD(dtdate))
This.DateHeaderText = "Veterans Day (Observed)"
ENDCASE
liCount = 0
FOR liDay = 1 TO 30
IF DOW(DATE(liYear, liMonth, liDay)) = 5
liCount = liCount + 1
IF liCount = 4
EXIT
ENDIF
ENDIF
ENDFOR
IF TTOD(dtdate) = DATE(liYear, liMonth, liDay)
This.DateHeaderText = "Thanksgiving Day"
ENDIF
CASE liMonth = 12
IF TTOD(dtdate) = DATE(liYear, liMonth, 25)
This.DateHeaderText = "Christmas Day"
ENDIF
DO CASE
CASE DOW(DATE(liYear, liMonth, 25)) = 7 AND (DATE(liYear, liMonth, 25) - 1 = TTOD(dtdate))
This.DateHeaderText = "Christmas Day (Observed)"
CASE DOW(DATE(liYear, liMonth, 25)) = 1 AND (DATE(liYear, liMonth, 25) + 1 = TTOD(dtdate))
This.DateHeaderText = "Christmas Day (Observed)"
ENDCASE
IF DOW(DATE((liYear + 1), 1, 1)) = 7 AND (DATE((liYear + 1), 1, 1) - 1 = TTOD(dtdate))
This.DateHeaderText = "New Years Day (Observed)"
ENDIF
ENDCASE
[b][COLOR=#4E9A06]*
* read the calendar events from Outlook
* and insert into a cursor, using the iCal4VFP library
*[/color][/b]
DO LOCFILE("iCalLoader.prg")
LOCAL iCsProc AS ICSProcessor
LOCAL iCal AS iCalendar
[b][COLOR=#4E9A06]* create an ICS format processor[/color][/b]
m.iCsProc = CREATEOBJECT("ICSProcessor")
[b][COLOR=#4E9A06]* export the Calendar from Outlook in iCalendar format[/color][/b]
LOCAL Outlook AS Outlook.Application
LOCAL NS AS Outlook.Namespace
LOCAL Folder AS Outlook.Folder
LOCAL ExpCal AS Outlook.CalendarSharing
LOCAL OutlookICS AS String
m.Outlook = CREATEOBJECT("Outlook.Application")
m.NS = m.Outlook.GetNamespace("MAPI")
m.Folder = m.NS.GetDefaultFolder(9) [b][COLOR=#4E9A06]&& calendar[/color][/b]
m.ExpCal = m.Folder.GetCalendarExporter()
m.ExpCal.CalendarDetail = 2 [b][COLOR=#4E9A06]&& full details[/color][/b]
m.ExpCal.StartDate = DATE(YEAR(DATE()), 1, 1)
m.ExpCal.EndDate = DATE(YEAR(DATE()), 12, 31)
m.ExpCal.IncludeWholeCalendar = .T.
m.OutlookICS = ADDBS(SYS(2023)) + "~outlook.ics"
m.ExpCal.SaveAsICal(m.OutlookICS)
STORE .NULL. TO ;
m.ExpCal, m.Folder, m.NS, m.Outlook
[b][COLOR=#4E9A06]* read the holidays/events definitions[/color][/b]
m.iCal = m.iCsProc.ReadFile(m.OutlookICS)
[b][COLOR=#4E9A06]* prepare a cursor to get all events[/color][/b]
CREATE CURSOR CalEvents (eventDate date, eventType Varchar(64), eventName varchar(64))
INDEX ON eventDate TAG eventDate
LOCAL CalEvent AS ICComponent
LOCAL EventIndex AS Integer
LOCAL ARRAY Categories[1]
[b][COLOR=#4E9A06]* for every event in the calendar[/color][/b]
FOR m.EventIndex = 1 TO m.iCal.GetICComponentsCount("VEVENT")
m.CalEvent = m.iCal.GetICComponent("VEVENT", m.EventIndex)
m.Categories = m.CalEvent.GetICPropertyValue("CATEGORIES")
[b][COLOR=#4E9A06]* insert in our cursor, for future use[/color][/b]
INSERT INTO CalEvents (eventDate, eventType, eventName) ;
VALUES (m.CalEvent.GetICPropertyValue("DTSTART"), ;
m.Categories[1], ;
m.CalEvent.GetICPropertyValue("SUMMARY"))
ENDFOR
[b][COLOR=#4E9A06]* browse the results[/color][/b]
SELECT CalEvents
GO TOP
BROWSE
BEGIN:VEVENT
DTSTART;VALUE=DATE:19860120
RRULE:FREQ=YEARLY;BYMONTH=1;BYDAY=MO;BYSETPOS=3
SUMMARY:Martin Luther King Jr. Day (U.S.)
UID:20111111000000Z-US_COMMON_HOLIDAYS-02@sappjw
END:VEVENT
[b][COLOR=#73D216]*
* read the calendar events from an iCalendar file
* and insert them into a cursor, using the iCal4VFP library
*[/color][/b]
DO LOCFILE("iCalLoader.prg")
LOCAL iCsProc AS ICSProcessor
LOCAL iCal AS iCalendar
[b][COLOR=#73D216]* create an ICS format processor[/color][/b]
m.iCsProc = CREATEOBJECT("ICSProcessor")
[b][COLOR=#73D216]* read the holidays definitions[/color][/b]
m.iCal = m.iCsProc.ReadUrl("[URL unfurl="true"]https://github.com/sappjw/calendars/raw/master/US_Holidays.ics")[/URL]
[b][COLOR=#73D216]* prepare a cursor to get all events[/color][/b]
CREATE CURSOR USEvents (eventDate date, eventName varchar(64))
INDEX ON eventDate TAG eventDate
LOCAL USEvent AS ICComponent
LOCAL EventRule AS ICProperty
LOCAL EventIndex AS Integer
LOCAL RuleIndex AS Integer
LOCAL RuleCursor AS String
[b][COLOR=#73D216]* for every event (from New Year's day to Christmas)[/color][/b]
FOR m.EventIndex = 1 TO m.iCal.GetICComponentsCount("VEVENT")
m.USEvent = m.iCal.GetICComponent("VEVENT", m.EventIndex)
[b][COLOR=#73D216]* for every rule that defines it (usually, just one)[/color][/b]
FOR m.RuleIndex = 1 TO m.USEvent.GetICPropertiesCount("RRULE")
m.EventRule = m.USEvent.GetICProperty("RRULE", m.RuleIndex)
[b][COLOR=#73D216]* calculate all recurrences since its start date through all 21st. century[/color][/b]
m.RuleCursor = m.EventRule.CalculateAll(m.USEvent.GetICPropertyValue("DTSTART"), {^2100-12-31})
[b][COLOR=#73D216]* insert in our cursor, for future use[/color][/b]
INSERT INTO USEvents (eventDate, eventName) ;
SELECT DISTINCT localTime, CAST(m.USEvent.GetICPropertyValue("SUMMARY") AS Varchar(64)) ;
FROM (m.RuleCursor)
USE IN SELECT(m.RuleCursor)
ENDFOR
ENDFOR
[b][COLOR=#73D216]* browse the results[/color][/b]
SELECT USEvents
GO TOP
BROWSE
Mike Lewis said:just an example of the fascinating facts that a simple FoxPro question can throw up