Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- proc vmc_holidays { year } {
- set res {}
- # Memorial day, labor day, Thanksgiving
- foreach { month dow lim ind } {
- 05 1 31 end
- 09 1 30 0
- 11 4 30 3
- } {
- set s2 {}
- # get the numeric day of the week for the first of the month
- set s [clock format [clock scan [format "%s%s01" $year $month]] -format %w]
- # find the day of month of the first monday or thurs
- set day [expr (7+$dow-$s)%7+1]
- while { $day <= $lim } {
- # add the date of each matching day of the week in the month to a list
- lappend s2 [format "%s%s%02d" $year $month $day]
- incr day 7
- }
- # pick out just date specified by "ind" above
- lappend res [lindex $s2 $ind]
- }
- # new years, independence, christmas & eve, new years observed
- foreach x { 0101 0704 1225 1231 } {
- set d "$year$x"
- set s [clock scan $d]
- set dow [clock format $s -format %a]
- if { $x eq "1231" && $dow ne "Fri" } {
- # new years day observed on Fri, 12/31
- continue
- }
- if { $x eq "1225" } {
- # compute where christmas and christmas eve fall
- if { $dow eq "Sat" } {
- lappend res [clock format [clock add $s -2 days] -format %Y%m%d]
- set s [clock add $s -1 day]
- } elseif { $dow eq "Sun" } {
- lappend res [clock format [clock add $s -2 days] -format %Y%m%d]
- set s [clock add $s 1 day]
- } elseif { $dow eq "Mon" } {
- lappend res [clock format [clock add $s 1 days] -format %Y%m%d]
- } else {
- lappend res [clock format [clock add $s -1 days] -format %Y%m%d]
- }
- } elseif { $dow eq "Sat" } {
- if { $x eq "0101" } {
- # this was observed last year
- continue
- }
- set s [clock add $s -1 day]
- } elseif { $dow eq "Sun" } {
- set s [clock add $s 1 day]
- }
- lappend res [clock format $s -format %Y%m%d]
- }
- return [lsort $res]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement