[1/3] from: kpeters:otaksoft at: 26-Sep-2007 21:17
I have a strong feeling that my code below can be significantly shortened and optimized - any suggestions? TIA, Kai Create a block containing the days of the week for an entire month based on a given date. Disregard the missing leapyear handling - none of us will be around to see it screw up! Input: 2007-02-14 Output: [ "Thu" "Fri" ...... ] curdate: 2007-02-14 ; days-per-month: [ 31 28 31 30 31 31 30 31 30 31 ] weekdays: [ "Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun" ] m: curdate/month maxday: days-per-month/:m days: copy  for day 1 maxday 1 [ tdate: to-date rejoin [ curdate/year "-" curdate/month "-" day ] wd: tdate/weekday wd: weekdays/:wd append days wd ] probe days
[2/3] from: Tom::Conlin::gmail::com at: 28-Sep-2007 23:00
Kai Peters wrote:
> I have a strong feeling that my code below can be significantly > shortened and optimized - any suggestions?
<<quoted lines omitted: 20>>> ] > probe days
it will miss the leap day in feb when the year is divisible by four but the error does not propagate monthdays: func [ cal [date!] /local month-end weekday result ][ month-end: [30 27 30 29 30 29 30 30 29 30 29 30] weekday: make block! 8 foreach wd system/locale/days[insert tail weekday copy/part wd 3] insert tail weekday first weekday result: make block! 35 cal: to date! reduce[cal/1 cal/2 1] insert/only result weekday/(cal/weekday) loop month-end/(cal/2)[ insert/only tail result select weekday last result ] result ]
[3/3] from: gregg:pointillistic at: 29-Sep-2007 8:09
Hi Kai, How about this? (uses my COLLECT function, easy to work around though) day-names: func [date [date!] /local days] [ days: copy/deep system/locale/days forall days [clear at days/1 4] date/day: 1 collect name [ until [ name: pick days date/weekday date: date + 1 ; When day is back to 1, we've hit the next month date/day = 1 ] ] ] -- Gregg
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted