>Here is something more efficient :
>
>>> firstOfNextMonth: firstOfMonth/month: firstOfMonth/month + 1
>== 1-Mar-2000
>>> daysInMonth: firstOfNextMonth - firstOfMonth
>== 29
>
>
>print [" There are " daysInMonth " days in " currentMonth now/year]
>
>Olivier
Thanks for the elegant code above... run the following... an oddity occurs...
 
REBOL [
   Title:  "What's the proper way to do the date function to avoid first month of year - last month of previous year oddity?"
   Date:   19-Feb-2000
   Version: 0.0.1
   Author: "John Braman"
   Email:  [EMAIL PROTECTED]
]
 
weekdays: [Monday Tuesday Wednesday Thursday Friday Saturday Sunday]
; weeks in this calendar start with Monday, if you want them to start with any other day then use the series or offset to the appropriate day of week. Or change this block to start with the day of the week that you want it to.
 
months: [January February March April May June July August September October November December]
 
; get month and year from user
PRINT "To expose bug type 1st month of any year, like 1 2000, or 1 1999, etc."
userDate: PARSE ASK " Enter Month as MM YYYY, or q to exit : " NONE
 
IF (first userDate) = "q" [ PRINT "HTMLCalendar.r" HALT ]
; use appropriate datatype
month:   MAKE INTEGER! FIRST userDate
year: MAKE INTEGER! SECOND userDate
 
; join the input and make it to be the first day of the month
 
inputDate: JOIN 1 [ "-" month "-" year ]
firstOfMonth: MAKE DATE! inputDate
 
PRINT ["So you are intrested in is "  PICK months (firstOfMonth/month) year]
 
; find first of next month and first of previous month
; this will help us to find the number of days in month to make calendar and should automatically account for leap years.
; note this works for all months except the first month of any year.

firstOfNextMonth: firstOfMonth/month: firstOfMonth/month + 1
firstOfPrevMonth: firstOfMonth/month: firstOfMonth/month - 1
 
; find days in month and days in previous month
daysInMonth: firstOfNextMonth - firstOfMonth
daysInPrevMonth: firstOfMonth - firstOfPrevMonth
 
; convert the month to words, save it.
monthName: PICK months (month)
prevMonthName: PICK months (firstOfPrevMonth/month) ; use date value incase month-1=0
nextMonthName: PICK months (firstOfNextMonth/month)
 
; print the values just to check them
PRINT ["There are " daysInPrevMonth " days in the previous month of " prevMonthName  firstOfPrevMonth/year]
PRINT ["There are " daysInMonth " days in " monthName firstOfMonth/year ]

Reply via email to