### Author Topic: Last Monday of each week  (Read 3632 times)

0 Members and 1 Guest are viewing this topic.

#### Andrea

• Water Moccasin
• Posts: 2372
##### Last Monday of each week
« on: May 27, 2010, 11:00:37 PM »
Hi all..
I didn't see any think similar on the web...
so i've decided to post this code here.

The code below Show the last Monday Date.
If any of you have some diffrent way ...i'll be curius to see.

Code: [Select]
`(setq uMonth (menucmd "M=\$(edtime,\$(getvar,date),MO\)")      uDay   (strcase (menucmd "M=\$(edtime,\$(getvar,date),DDD\)") t)      uDate  (atoi (menucmd "M=\$(edtime,\$(getvar,date),DD\)"))      uYear  (menucmd "M=\$(edtime,\$(getvar,date),YYYY\)"))(cond  ((= uMonth "01")(setq uMonthday 31 pMonth "12"))  ((= uMonth "02")(setq uMonthday 31 pMonth "01"))  ((= uMonth "03")(setq uMonthday 28 pMonth "02"))  ((= uMonth "04")(setq uMonthday 31 pMonth "03"))  ((= uMonth "05")(setq uMonthday 30 pMonth "04"))  ((= uMonth "06")(setq uMonthday 31 pMonth "05"))  ((= uMonth "07")(setq uMonthday 30 pMonth "06"))  ((= uMonth "08")(setq uMonthday 31 pMonth "07"))  ((= uMonth "09")(setq uMonthday 31 pMonth "08"))  ((= uMonth "10")(setq uMonthday 30 pMonth "09"))  ((= uMonth "11")(setq uMonthday 31 pMonth "10"))  ((= uMonth "12")(setq uMonthday 30 pMonth "11")))(setq uDpos (vl-position uDay '("mon" "tue" "wed" "thu" "fri" "sat" "sun")))(if (< (setq uDdiff (- uDate uDpos)) 0)     (setq uDate (+ uMonthday uDdiff)          uMonth pMonth)  (setq uDate (- uDate uDpos)))(alert (strcat "Monday the " (itoa uDate) " of " uMonth " Month " uYear))`
Keep smile...

#### uncoolperson

• Guest
##### Re: Last Monday of each week
« Reply #1 on: May 27, 2010, 11:23:46 PM »
how can there be a last monday of each week?

(not intending to be mean)
« Last Edit: May 27, 2010, 11:52:24 PM by uncoolperson »

#### Daniel J. Ellis

• Swamp Rat
• Posts: 811
##### Re: Last Monday of each week
« Reply #2 on: May 28, 2010, 02:56:50 AM »
I think it's meant to go something like: "Today is Friday 28th May, so is in the week commencing Monday 24th May"

dJE
===
dJE

#### Lee Mac

• Seagull
• Posts: 12912
• London, England
##### Re: Last Monday of each week
« Reply #3 on: May 28, 2010, 06:35:53 AM »
Nice idea, I suppose it could be made slightly more concise:

Code: [Select]
`(defun c:Mon ( / uMonth uDay uDate uYear uMonthday pMonth uDpos uDdiff )    (setq uMonth (menucmd "M=\$(edtime,\$(getvar,date),MO\)")        uDay   (strcase (menucmd "M=\$(edtime,\$(getvar,date),DDD\)") t)        uDate  (atoi (menucmd "M=\$(edtime,\$(getvar,date),DD\)"))        uYear  (menucmd "M=\$(edtime,\$(getvar,date),YYYY\)")  )  (setq uMonthday (nth (1+ (atoi uMonth)) '(31 31 28 31 30 31 30 31 31 30 31 30))        pMonth    (itoa (1+ (rem (+ 10 (atoi uMonth)) 12))))  (setq uDpos (vl-position uDay '("mon" "tue" "wed" "thu" "fri" "sat" "sun")))    (if (< (setq uDdiff (- uDate uDpos)) 0)     (setq uDate (+ uMonthday uDdiff) uMonth pMonth)    (setq uDate (- uDate uDpos))  )    (alert (strcat "Monday the " (itoa uDate) " of " uMonth " Month " uYear))  (princ))`

#### Lee Mac

• Seagull
• Posts: 12912
• London, England
##### Re: Last Monday of each week
« Reply #4 on: May 28, 2010, 06:53:55 AM »

Code: [Select]
`(alert  (menucmd    (strcat "M=\$(edtime,"      (rtos        (- (getvar 'DATE)          (vl-position (strcase (menucmd "M=\$(edtime,\$(getvar,date),DDD\)") t)            '("mon" "tue" "wed" "thu" "fri" "sat" "sun")          )        )        2 15      )      ",DD/MO/YYYY)"    )  ))`
« Last Edit: May 28, 2010, 07:07:37 AM by Lee Mac »

#### Andrea

• Water Moccasin
• Posts: 2372
##### Re: Last Monday of each week
« Reply #5 on: May 28, 2010, 09:34:34 AM »
wow Lee Nice !   :ugly:

Keep smile...

#### VovKa

• Water Moccasin
• Posts: 1628
• Ukraine
##### Re: Last Monday of each week
« Reply #6 on: May 28, 2010, 10:09:13 AM »
Code: [Select]
`(alert  (menucmd (strcat "M=\$(edtime,"    (rtos (- (getvar 'DATE) (fix (rem (getvar 'DATE) 7))) 2 15)    ",DD/MO/YYYY)"    )  ))`

#### Andrea

• Water Moccasin
• Posts: 2372
##### Re: Last Monday of each week
« Reply #7 on: May 28, 2010, 10:23:14 AM »
Code: [Select]
`(alert  (menucmd (strcat "M=\$(edtime,"    (rtos (- (getvar 'DATE) (fix (rem (getvar 'DATE) 7))) 2 15)    ",DD/MO/YYYY)"    )  ))`

OMG !!  i'm out on this one..
nice coding Vovka !
Keep smile...

#### Lee Mac

• Seagull
• Posts: 12912
• London, England
##### Re: Last Monday of each week
« Reply #8 on: May 28, 2010, 12:04:32 PM »
Code: [Select]
`(rtos (- (getvar 'DATE) (fix (rem (getvar 'DATE) 7))) 2 15)`

Ah! I should have thought of that one - nice on VovKa you have trumped me yet again

#### VovKa

• Water Moccasin
• Posts: 1628
• Ukraine
##### Re: Last Monday of each week
« Reply #9 on: May 28, 2010, 12:31:51 PM »
Code: [Select]
`(rtos (- (getvar 'DATE) (fix (rem (getvar 'DATE) 7))) 2 15)`

Ah! I should have thought of that one - nice on VovKa you have trumped me yet again
(setq MyEgo (1+ MyEgo))

#### Krushert

• Seagull
• Posts: 13679
• FREE BEER Tomorrow!!
##### Re: Last Monday of each week
« Reply #10 on: May 28, 2010, 01:48:02 PM »
I am home for day so I can test the the above code.  What is the purpose or the final goal?
I am asking becuase if it is what I think it is, then I might have a use for something like this.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

#### Lee Mac

• Seagull
• Posts: 12912
• London, England
##### Re: Last Monday of each week
« Reply #11 on: May 28, 2010, 01:56:56 PM »
I'm guessing it might be useful when filling out a timesheet for week commencing...

#### Andrea

• Water Moccasin
• Posts: 2372
##### Re: Last Monday of each week
« Reply #12 on: May 31, 2010, 03:22:09 PM »
I am home for day so I can test the the above code.  What is the purpose or the final goal?
I am asking becuase if it is what I think it is, then I might have a use for something like this.

In Fact,...I have a prog who it write on TXT file all print data with:
date,loginname,papersize,paperstyle,printer name, number of copies,total area,...etc.
who can be imported in to an excel sheet and determine total cost by project, by date etc..
1 file by week, and the name need to be the Monday date. eg: 2010-05-31-Printdata.csv
Keep smile...