|
Joined: Aug 2004
Posts: 7,168
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2004
Posts: 7,168 |
var %day = $findtok(Sunday Monday Tuesday Wednesday Thursday Friday Saturday,$day,1,32)
if $1 == 1 {
did -a $dname 71 $asctime($calc($ctime + 0),d)
did -a $dname 72 $asctime($calc($ctime + 86400),d)
did -a $dname 73 $asctime($calc($ctime + 172800),d)
did -a $dname 74 $asctime($calc($ctime + 259200),d)
did -a $dname 75 $asctime($calc($ctime + 345600),d)
did -a $dname 76 $asctime($calc($ctime + 432000),d)
did -a $dname 77 $asctime($calc($ctime + 518400),d)
}
elseif %day == 2 {
did -a $dname 71 $asctime($calc($ctime - 86400),d)
did -a $dname 72 $asctime($calc($ctime + 0),d)
did -a $dname 73 $asctime($calc($ctime + 86400),d)
did -a $dname 74 $asctime($calc($ctime + 172800),d)
did -a $dname 75 $asctime($calc($ctime + 259200),d)
did -a $dname 76 $asctime($calc($ctime + 345600),d)
did -a $dname 77 $asctime($calc($ctime + 432000),d)
}
elseif %day == 3 {
did -a $dname 71 $asctime($calc($ctime - 172800),d)
did -a $dname 72 $asctime($calc($ctime - 86400),d)
did -a $dname 73 $asctime($calc($ctime + 0),d)
did -a $dname 74 $asctime($calc($ctime + 86400),d)
did -a $dname 75 $asctime($calc($ctime + 172800),d)
did -a $dname 76 $asctime($calc($ctime + 259200),d)
did -a $dname 77 $asctime($calc($ctime + 345600),d)
}
elseif %day == 4 {
did -a $dname 71 $asctime($calc($ctime - 259200),d)
did -a $dname 72 $asctime($calc($ctime - 172800),d)
did -a $dname 73 $asctime($calc($ctime - 86400),d)
did -a $dname 74 $asctime($calc($ctime + 0),d)
did -a $dname 75 $asctime($calc($ctime + 86400),d)
did -a $dname 76 $asctime($calc($ctime + 172800),d)
did -a $dname 77 $asctime($calc($ctime + 259200),d)
}
elseif %day == 5 {
did -a $dname 71 $asctime($calc($ctime - 345600),d)
did -a $dname 72 $asctime($calc($ctime - 259200),d)
did -a $dname 73 $asctime($calc($ctime - 172800),d)
did -a $dname 74 $asctime($calc($ctime - 86400),d)
did -a $dname 75 $asctime($calc($ctime + 0),d)
did -a $dname 76 $asctime($calc($ctime + 86400),d)
did -a $dname 77 $asctime($calc($ctime + 172800),d)
}
elseif %day == 6 {
did -a $dname 71 $asctime($calc($ctime - 432000),d)
did -a $dname 72 $asctime($calc($ctime - 345600),d)
did -a $dname 73 $asctime($calc($ctime - 259200),d)
did -a $dname 74 $asctime($calc($ctime - 172800),d)
did -a $dname 75 $asctime($calc($ctime - 86400),d)
did -a $dname 76 $asctime($calc($ctime + 0),d)
did -a $dname 77 $asctime($calc($ctime + 86400),d)
}
elseif %day == 7 {
did -a $dname 71 $asctime($calc($ctime - 518400),d)
did -a $dname 72 $asctime($calc($ctime - 432000),d)
did -a $dname 73 $asctime($calc($ctime - 345600),d)
did -a $dname 74 $asctime($calc($ctime - 259200),d)
did -a $dname 75 $asctime($calc($ctime - 172800),d)
did -a $dname 76 $asctime($calc($ctime - 86400),d)
did -a $dname 77 $asctime($calc($ctime + 0),d)
}
There are a lot of similar things happening in this code, and it does work as written, but if I could get this reduced in size I'd appreciate it.. The overall code is going to be very long to start with.
|
|
|
|
Byte187
|
Byte187
|
Try something like this...
var %day = $findtok(Sunday Monday Tuesday Wednesday Thursday Friday Saturday, $day, 1, 32)
var %base = $calc(70 + %day)
var %i = 0
while (%i < 7) {
did -a $dname %base $asctime($calc($ctime + (86400 * %i)),d)
inc %i
inc %base
if (%base > 77) %base = 71
}
Last edited by Byte187; 04/08/08 05:40 AM.
|
|
|
|
Joined: Aug 2004
Posts: 7,168
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2004
Posts: 7,168 |
That's great with one (small?) problem. If the current date doesn't match Sunday, then the days previous to the current date show the dates for the following week, not the current week.
Eg: Monday Aug. 8, 2008 is today's date, and with your code Sunday's date shows as Aug. 14th not Aug. 7th (which I would prefer)
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
Try this:
var %c = 0
while (%c < 7) {
inc %c
echo -a did -a $dname $calc(70 + %c) $asctime($calc($ctime + ((%c - $1) * 86400)),d)
}
It should bolt in, right in place of all the if/elseifs. -genius_at_work
|
|
|
|
Byte187
|
Byte187
|
That's because, on Sunday, the code for Sunday is
$asctime($calc($ctime + 0),d)
But on Monday, the code for Sunday is
$asctime($calc($ctime - 86400),d)
You'll have to account for the use + or - where appropriate.
Last edited by Byte187; 04/08/08 05:38 AM.
|
|
|
|
Joined: Aug 2004
Posts: 7,168
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2004
Posts: 7,168 |
Sorry, but after removing the echo -a and exchanging the $1 for %day (which I forgot to do in my original post's 2nd line), this showed today's date as the 4th, not the 8th
|
|
|
|
Joined: Nov 2006
Posts: 1,552
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,552 |
maybe this solves it (modifying Byte187s suggestion): var %day = $findtok(Sunday Monday Tuesday Wednesday Thursday Friday Saturday, $day, 1, 32)
var %did = $calc(70 + %day), %start = %did, %i = 0
while (%i < 7) {
did -a $dname %did $asctime($calc($ctime + (86400 * (%did - %start))),d)
inc %i
inc %did
if (%did > 77) { var %did = 71 }
} Change your computer clock for tests, not just the %day (as it won't affect the $*ctime)
Last edited by Horstl; 04/08/08 06:14 AM.
|
|
|
|
Joined: Aug 2004
Posts: 7,168
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2004
Posts: 7,168 |
Like with genius_at_work's suggestion, the dates are out of sync. It shows today as being the 4th, not the 8th.
As I said, the date running into next week, as they do with Byte187's code, is a small problem.. and, in fact, more of an annoyance to my way of thinking than a real problem.
|
|
|
|
Joined: Nov 2006
Posts: 1,552
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,552 |
Hum, the item 71 is the "sunday did" and a week shall start at sunday? Adding an echo line "ECHO -a testing: $date(dd.mm.yy ddd) - did for $day is %did" I get:
testing: 04.08.08 Mon - did for Monday is 72 did -a dname 72 4 did -a dname 73 5 did -a dname 74 6 did -a dname 75 7 did -a dname 76 8 did -a dname 77 9 did -a dname 71 3 = the week "Sun, August 3th to Sat, August 9th"
setting now the system clock to august 1st I get:
testing: 01.08.08 Fri - did for Friday is 76 did -a dname 76 1 did -a dname 77 2 did -a dname 71 27 did -a dname 72 28 did -a dname 73 29 did -a dname 74 30 did -a dname 75 31 = the week "Sun, July 27th to Sat, August 2nd"
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
Today IS the 4th. My code duplicates yours exactly, so any error in mine is also present in yours.
alias day {
echo -a ---------
var %day = $findtok(sun.mon.tue.wed.thu.fri.sat,$asctime(ddd),1,46)
var %c = 0
while (%c < 7) {
inc %c
echo -a did -a $dname $calc(70 + %c) $asctime($calc($ctime + ((%c - %day) * 86400)),d)
}
}
-genius_at_work
|
|
|
|
Joined: Aug 2004
Posts: 7,168
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2004
Posts: 7,168 |
My apologies to all that looke/re-looked at the code(s) based on the fact that I was saying that it was returning today as the 4th, not the 8th. For some reason I was reading the current date incorrectly, thinking that the month was actually the day (the display on my computer is in dd/mm/yyyy format.
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
[offtopic] dd/mm/yyyy makes the most sense as it goes small/medium/large I am used to that date format from living in the UK though!  [/offtopic]
|
|
|
|
|