In REBOL you can get the numerical day of week quite simply, as follows ( copied/pasted from a REBOL console session) :
 
>> date: 8-dec-1917
== 8-Dec-1917
>> date/weekday
== 6
>>
 
; Saturday, just like mother told me!  Back then, the doctor came to the house, on weekends!
there are no spaces in date/weekday.  date is a variable of type date!  and /weekday is a "refinement" of a variable of that datatype that returns the day of week number.  I could have used 'x as the variable name, just as well as 'date.  Then x/weekday would have returned the same result.
 
----- Original Message -----
Sent: Saturday, February 19, 2000 6:47 PM
Subject: [REBOL] .r to html monthly calendar prelude

Do any rebols have examples of .r scripts that create monthly calendars that
they are willing to share?  Or even a few thoughts on how you would create one.
 
The following are some simple scripts I made yesterday as a prelude to html monthly calendar.  The work, however I'd love to see how other people are thinking about calendar.r that will create interactive monthly calendars for events, etc  Ideally some link to a database or (block?) or (series?) will be useful so that http:// visitors or administrator will be able to change the events visa the http:// link. 
 
But before you see the prelude to the calendar scripts, let's assume I want to provide access to an http://wateva.com/admincal.r how do I go about protecting that admincal.r file so only the persons with the proper username and password have access?  I'm talking about the internet here not a private intranet...  ideally the admincal.r will ask the person for a username and password.  If not correct it will send them to some index.htm or index.r file after a few tries.  If they are authorized via the proper username and password that they enter then it continues on with the rest if the script allowing them to update or delete events, etcetera.
 

REBOL [
    Title:  "day of the Week"
    Date:   18-Feb--2000
    Author: "J B"
    Version: 1.0.0
    Purpose: "Shows day of the week and number of days in months, it's a prelude to an HTML monthly calendar"
]
 
print "The ify way to show today is "
  if now/weekday = 1 [print "Monday"]
  if now/weekday = 2 [print "Tuesday"]
  if now/weekday = 3 [print "Wednesday"]
  if now/weekday = 4 [print "Thursday"]
  if now/weekday = 5 [print "Friday"]
  if now/weekday = 6 [print "Saturday"]
  if now/Weekday = 7 [print "Sunday"]
 
print [" The switch way to show today is "
   switch now/weekday [
 1 ["Monday"]
 2 ["Tuesday"]
 3 ["Wednesday"]
 4 ["Thursday"]
 5 ["Friday"]
 6 ["Saturday"]
 7 ["Sunday"]
   ]; ends switch
]; ends print
 
; QUESTION there's go to be more elegant ways of getting the named day than this?
print [newline "QUESTION there's go to be more elegant ways of getting the named day than the two ways I've shown here?" newline]
 
; convert the current month to words, save it.
switch now/month [
 1 [currentMonth: "January"]
 2 [currentMonth: "February"]
 3 [currentMonth: "March"]
 4 [currentMonth: "April"]
 5 [currentMonth: "Mayo"]
 6 [currentMonth: "June"]
 7 [currentMonth: "Julio"]
 8 [currentMonth: "Augusta"]
 9 [currentMonth: "September"]
 10 [currentMonth: "Octopus"]
 11 [currentMonth: "Novice"]
 12 [currentMonth: "Decent"]
        ] ; end switch of month
 
firstOfMonth: now - now/day + 1
 
Print ["the first day of " currentMonth now/year "was"
   switch firstOfMonth/weekday [
 1 ["Monday"]
 2 ["Tuesday"]
 3 ["Wednesday"]
 4 ["Thursday"]
  5 ["Friday"]
  6 ["Saturday"]
 7 ["Sunday"]
   ] ; ends the switch
] ; ends first day of month print
 
 
 
;figure out the number of days in this month and print
 
monthInQeustion: now/month
EOMtest: firstOfMonth + 27
 
print ["before using to-date is EOMtest a date? " date? EOMtest]
EOMtest: to-date EOMtest
print ["after to-date is EOMtest a date? " date? EOMtest]
; I'd like to assign the above to EOMtest: [firstOfMonth + 27]
; however then if I use EOMtest/month it claims 'invalid path value: month'
; I had to-date the EOMtest Now after working on this all day long I'm not sure
; about this so the following question maybe a bit silly...
;
; QUESTION why doesn't the type date value automatically transfer to the new variable?
;
; Note: the second time you run this both of the date? of EOMtest will be true,
; because EOMtest is now in a date type resulting from
; the previous run unless of course you've reset all the variables;-}
; which brings me to my next
 
; QUESTIION how do I easily clear or reset variables at the begining of the script?
 

month: monthInQuestion
while [month = monthInQuestion] [
  EOMtest: EOMtest + 1
  daysInMonth: EOMtest/day
  month: EOMtest/month
 ] ; ends code of while block
; go back one day for last day in month
EOMtest: EOMtest - 1
daysInMonth: EOMtest/day
print [" There are " daysInMonth " days in " currentMonth now/year]
 

; figuring out how many days in month
; one way that seems intutive if I could do somthing like
; goToEndOfMonth: make date! [dd mm yy] where dd mm and yy are actually variables
; and iterate using any of dd mm or yy... but that doesn't seem to work
; help on the above... line is appreciated
; than I could itereate any of these values.
; and test for when mm change the previous dd is the number of days in month
; instead I do the following...
; however, tmtowtdi so ... more elegant solutions will be greatly appreciated.
 
print "Enter a date in the following format  dd-mm-yy I'll tell you the day of the week of the first day, the last day and the number of days in that month."
print " go ahead dd-mm-yy "
 
inputDate: input
inputDate: to-date inputDate
dateInQuestion: inputDate
monthInQuestion: dateInQuestion/month
 
; convert the monthInQuestion to words, save it.
switch monthInQuestion [
 1 [MonthName: "January"]
 2 [MonthName: "February"]
 3 [MonthName: "March"]
 4 [MonthName: "April"]
 5 [MonthName: "Mayo"]
 6 [MonthName: "June"]
 7 [MonthName: "Julio"]
 8 [MonthName: "Augusta"]
 9 [MonthName: "September"]
 10 [MonthName: "Octopus"]
 11 [MonthName: "Novice"]
 12 [MonthName: "Decent"]
        ] ; end switch of month to words
 
print ["So you are interested in " MonthName dateInQuestion/year "?"]
 
firstDayInMonth: dateInQuestion - dateInQuestion/day + 1
Print ["the first day of " MonthName dateInQuestion/year " is "
   switch firstDayInMonth/weekday [
 1 ["Monday"]
 2 ["Tuesday"]
 3 ["Wednesday"]
 4 ["Thursday"]
  5 ["Friday"]
  6 ["Saturday"]
 7 ["Sunday"]
   ] ; ends the switch
] ; ends first day of monthInQuestion print
EOMtest: firstDayInMonth + 27
EOMtest: to-date EOMtest
month: EOMtest/month
while [month = monthInQuestion] [
  EOMtest: EOMtest + 1
  daysInMonth: EOMtest/day
  month: EOMtest/month
 ] ; ends code of while block
; go back one day for las day in month
EOMtest: EOMtest - 1
daysInMonth: EOMtest/day
print [" There are " daysInMonth "days in "MonthName dateInQuestion/year"."]
 
print ["tia your all the very best, any thoughts or insight is appreciated " newline "jb"]
 
 

Reply via email to