Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Floating holidays in the USA

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Floating holidays in the USA

    America appears to celebrate quite a couple of floating holidays. At a governmental website I found six of them. Floating means here: the yearly festivals are held on the same day (mostly on a Monday) but not on the same date. It is the type of calendar dates people are referring to as "4th Thursday of November" or "first Monday of September", and so forth.

    Using my Gregorian Date Library it's quite easy to write code in order to find those dates for a given year. Here's the code. Its output is a simple message box. By default it returns the calendar dates for the next year, but you can easily change that using your PB environment.

    Don't forget to download the Gregorian Library. Without including the file GREGORIAN.INC the code will refuse to work

    Code:
    ' this code is granted to the public domain
    ' use it at your own risk
    ' no warranty is given nor implied; 
    
    #COMPILE EXE
    #INCLUDE "GREGORIAN.INC"
    
    $PERL = CHR$(46, 13, 10)                                                       ' PEriod, Return, Linefeed
    %LOCALE_USA = 1033
    
    SUB CheckYear(BYVAL wMonth AS WORD, BYVAL wDay AS WORD, wYear AS WORD)
      LOCAL st AS SYSTEMTIME
      GetLocalTime st
      wYear = st.wYear
      IF Gregorian(st.wYear, wMonth, wDay) < _
         Gregorian(st.wYear, st.wMonth, st.wDay) THEN INCR wYear
    END SUB
    
    '*********************************************************************
    '* New Year's Day: January 1                                         *
    '*                                                                   *
    FUNCTION NwYear(iGreg AS LONG, OPTIONAL BYVAL wYear AS WORD) AS STRING
      LOCAL st AS SYSTEMTIME
      IF wYear = 0 THEN CheckYear 1, 1, wYear
      iGreg = Gregorian(wYear, 1, 1)
      GregorianToSysdate iGreg, st
      FUNCTION = "New Year" & CHR$(39) & "s Day: " & _
                 GregDateFormat(%DATE_LONGDATE, st, %LOCALE_USA)
    END FUNCTION
    
    '*********************************************************************
    '* Martin Luther King Day: 3rd Monday of January                     *
    '*                                                                   *
    FUNCTION MLKDay(iGreg AS LONG, OPTIONAL BYVAL wYear AS WORD) AS STRING
      LOCAL bOrdinal AS BYTE
      LOCAL wMonth AS WORD, wWeekDay AS WORD
      LOCAL st AS SYSTEMTIME
      wMonth   = 1                                                                 ' January
      wWeekDay = 1                                                                 ' Monday
      bOrdinal = 3                                                                 ' 3rd
      iGreg    = WeekDayOfMonth(wMonth, wWeekDay, bOrdinal, wYear)
      GregorianToSysdate iGreg, st
      FUNCTION = "Martin Luther King Day: " & _
                 GregDateFormat(%DATE_LONGDATE, st, %LOCALE_USA)
    END FUNCTION
    
    '**********************************************************************
    '* Presidents' Day: 3rd Monday of February                            *
    '*                                                                    *
    FUNCTION PresDay(iGreg AS LONG, OPTIONAL BYVAL wYear AS WORD) AS STRING
      LOCAL st AS SYSTEMTIME
      iGreg = WeekDayOfMonth(2, 1, 3, wYear)
      GregorianToSysdate iGreg, st
      FUNCTION = "Presidents" & CHR$(39) & " Day: " & _
                 GregDateFormat(%DATE_LONGDATE, st, %LOCALE_USA)
    END FUNCTION
    
    '*********************************************************************
    '* Valentine's Day: February 14                                      *
    '*                                                                   *
    FUNCTION ValDay(iGreg AS LONG, OPTIONAL BYVAL wYear AS WORD) AS STRING
      LOCAL st AS SYSTEMTIME
      IF wYear = 0 THEN CheckYear 2, 14, wYear
      iGreg = Gregorian(wYear, 2, 14)
      GregorianToSysdate iGreg, st
      FUNCTION = "Valentine" & CHR$(39) & "s Day: " & _
                 GregDateFormat(%DATE_LONGDATE, st, %LOCALE_USA)
    END FUNCTION
    
    '*********************************************************************
    '* Memorial Day: 4th Monday of May                                   *
    '*                                                                   *
    FUNCTION MemDay(iGreg AS LONG, OPTIONAL BYVAL wYear AS WORD) AS STRING
      LOCAL st AS SYSTEMTIME
      iGreg = WeekDayOfMonth(5, 1, 4, wYear)
      GregorianToSysdate iGreg, st
      FUNCTION = "Memorial Day: " & _
                 GregDateFormat(%DATE_LONGDATE, st, %LOCALE_USA)
    END FUNCTION
    
    '*********************************************************************
    '* Independence Day: July 4                                          *
    '*                                                                   *
    FUNCTION IndDay(iGreg AS LONG, OPTIONAL BYVAL wYear AS WORD) AS STRING
      LOCAL st AS SYSTEMTIME
      IF wYear = 0 THEN CheckYear 7, 4, wYear
      iGreg = Gregorian(wYear, 7, 4)
      GregorianToSysdate iGreg, st
      FUNCTION = "Independence Day: " & _
                 GregDateFormat(%DATE_LONGDATE, st, %LOCALE_USA)
    END FUNCTION
    
    '*********************************************************************
    '* Labor Day: 1st Monday of September                                *
    '*                                                                   *
    FUNCTION LabDay(iGreg AS LONG, OPTIONAL BYVAL wYear AS WORD) AS STRING
      LOCAL st AS SYSTEMTIME
      iGreg = WeekDayOfMonth(9, 1, 1, wYear)
      GregorianToSysdate iGreg, st
      FUNCTION = "Labor Day: " & _
                 GregDateFormat(%DATE_LONGDATE, st, %LOCALE_USA)
    END FUNCTION
    
    '************************************************************************
    '* Columbus Day: 2nd Monday of October                                  *
    '*                                                                      *
    FUNCTION ColumbDay(iGreg AS LONG, OPTIONAL BYVAL wYear AS WORD) AS STRING
      LOCAL st AS SYSTEMTIME
      iGreg = WeekDayOfMonth(10, 1, 2, wYear)
      GregorianToSysdate iGreg, st
      FUNCTION = "Columbus Day: " & _
                 GregDateFormat(%DATE_LONGDATE, st, %LOCALE_USA)
    END FUNCTION
    
    '*********************************************************************
    '* Halloween: October 31                                             *
    '*                                                                   *
    FUNCTION Hallow(iGreg AS LONG, OPTIONAL BYVAL wYear AS WORD) AS STRING
      LOCAL st AS SYSTEMTIME
      IF wYear = 0 THEN CheckYear 10, 31, wYear
      iGreg = Gregorian(wYear, 10, 31)
      GregorianToSysdate iGreg, st
      FUNCTION = "Halloween: " & _
                 GregDateFormat(%DATE_LONGDATE, st, %LOCALE_USA)
    END FUNCTION
    
    '*********************************************************************
    '* Veterans Day: November 11                                         *
    '*                                                                   *
    FUNCTION Vetran(iGreg AS LONG, OPTIONAL BYVAL wYear AS WORD) AS STRING
      LOCAL st AS SYSTEMTIME
      IF wYear = 0 THEN CheckYear 11, 11, wYear
      iGreg = Gregorian(wYear, 11, 11)
      GregorianToSysdate iGreg, st
      FUNCTION = "Veterans Day: " & _
                 GregDateFormat(%DATE_LONGDATE, st, %LOCALE_USA)
    END FUNCTION
    
    
    '*********************************************************************
    '* Thanksgiving Day: 4th Thursday of November                        *
    '*                                                                   *
    FUNCTION Thanks(iGreg AS LONG, OPTIONAL BYVAL wYear AS WORD) AS STRING
      LOCAL st AS SYSTEMTIME
      iGreg = WeekDayOfMonth(11, 4, 4, wYear)
      GregorianToSysdate iGreg, st
      FUNCTION = "Thanksgiving Day: " & _
                 GregDateFormat(%DATE_LONGDATE, st, %LOCALE_USA)
    END FUNCTION
    
    '**********************************************************************
    '* Christmas Day: December 25                                         *
    '*                                                                    *
    FUNCTION XMasDay(iGreg AS LONG, OPTIONAL BYVAL wYear AS WORD) AS STRING
      LOCAL st AS SYSTEMTIME
      IF wYear = 0 THEN CheckYear 12, 25, wYear
      iGreg = Gregorian(wYear, 12, 25)
      GregorianToSysdate iGreg, st
      FUNCTION = "Christmas Day: " & GregDateFormat(%DATE_LONGDATE, st, %LOCALE_USA)
    END FUNCTION
    
    FUNCTION PBMain() AS LONG
      LOCAL wYear AS WORD
      LOCAL sOutput AS STRING
      LOCAL iGreg AS LONG, count AS LONG
      DIM arr_Text(1 TO 12) AS STRING, arrIndex(1 TO 12) AS LONG
    
      wYear = 0000                                                                 ' (or type a year of choice)
    
      arr_Text(01) = NwYear(iGreg, wYear)
      arrIndex(01) = iGreg
      arr_Text(02) = MLKDay(iGreg, wYear)
      arrIndex(02) = iGreg
      arr_Text(03) = PresDay(iGreg, wYear)
      arrIndex(03) = iGreg
      arr_Text(04) = ValDay(iGreg, wYear)
      arrIndex(04) = iGreg
      arr_Text(05) = MemDay(iGreg, wYear)
      arrIndex(05) = iGreg
      arr_Text(06) = IndDay(iGreg, wYear)
      arrIndex(06) = iGreg
      arr_Text(07) = LabDay(iGreg, wYear)
      arrIndex(07) = iGreg
      arr_Text(08) = ColumbDay(iGreg, wYear)
      arrIndex(08) = iGreg
      arr_Text(09) = Hallow(iGreg, wYear)
      arrIndex(09) = iGreg
      arr_Text(10) = Vetran(iGreg, wYear)
      arrIndex(10) = iGreg
      arr_Text(11) = Thanks(iGreg, wYear)
      arrIndex(11) = iGreg
      arr_Text(12) = XMasDay(iGreg, wYear)
      arrIndex(12) = iGreg
    
      ARRAY SORT arrIndex(), TAGARRAY arr_Text()
      FOR count = 1 TO 12
        sOutput = sOutput & arr_Text(count) & $PERL
      NEXT
      MsgBox sOutput, 64, " Upcoming Holidays USA"
    END FUNCTION
    Last edited by Egbert Zijlema; 11 Dec 2007, 03:20 PM. Reason: adding a "granted to the public domain" statement

    Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
    http://zijlema.basicguru.eu
    *** Opinions expressed here are not necessarily untrue ***

  • #2
    I looked at floating holiday file and then downloaded gregorian.zip and pulled up gregorian.inc.

    What is copyright/redistribution status of this code, please (can't find it in #INCLUDE file)?

    Thanks,
    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment

    Working...
    X
    😀
    🥰
    🤢
    😎
    😡
    👍
    👎