>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"
>]

This hader is wrong : remark the double '-' before the year. When I exec it
the date displayed is :
>> do %tmp.r
Script: "day of the Week" (18-Feb-63536)

Is it an y2k bug ?

:^)


>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"]

This is not the more efficient way to do that.


>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

That is better.


>; 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]

Try this :

print [" The switch way to show today is"
   select [ 1 "Monday" 2 "Tuesday" 3 "Wednesday" 4 "Thursday" 5 "Friday" 6
"Saturday" 7 "Sunday"   ] now/weekday
]; ends print


And this is the best :

print [" The switch way to show today is"
   pick [ "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"
"Sunday" ] now/weekday
]; ends print



>; 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

currentMonth: pick [ "January" "February" "March" "April" "Mayo" "June"
"Julio" "Augusta" "September" "Octopus" "Novice" "Decent" ] now/month

> firstOfMonth: now - now/day + 1

Here is an other way:

>> firstOfMonth: now/date
== 20-Feb-2000
>> firstOfMonth: firstOfMonth/day: 1
== 1-Feb-2000

>;figure out the number of days in this month and print

>monthInQeustion: now/month
>EOMtest: firstOfMonth + 27

[...]

>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


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



Reply via email to