emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Last workday of the month
@ 2010-10-30 18:55 Chris Maier
  2010-10-30 20:19 ` Nick Dokos
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Maier @ 2010-10-30 18:55 UTC (permalink / raw)
  To: emacs-orgmode

I'm trying to come up with a sexp diary entry that shows my payday,
which is the last weekday of the month, in my Org agenda.  I've tried
to adapt the example given in the Emacs manual and this is what I came
up with:

%%(let ((month (car date))
        (day (cadr date))
        (dayname (calendar-day-of-week date)))
    (or
     ;; months with 31 days
     (and (memq month '(1 3 5 7 8 10 12))
             (or (and (= day 31)
                      (memq dayname '(1 2 3 4 5)))
                 (and (memq day '(29 30))
                      (= dayname 5))))
     ;; months with 30 days
     (and (memq month '(4 6 9 11))
          (or (and (= day 30)
                   (memq dayname '(1 2 3 4 5)))
              (and (memq day '(28 29))
                   (= dayname 5))))
     ;; February (the weird one)
     (and (= month 2)
          (or (and (memq day '(28 29))
                   (memq dayname '(1 2 3 4 5)))
              (and (memq day '(26 27 28))
                   (= dayname 5)))))) Chris' Paycheck Deposited

It appears to work so far.  However, I'm certain there's got to be a
more concise way of coding this, but I can't seem to find any
pre-existing calendar functions that might help.  Am I missing
something?

To make this even better, is there some way to consult another file of
diary entries containing all the holidays at my workplace, so the
diary entry would show up on the last weekday of the month that is not
a company holiday?

Thanks!

Chris

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Last workday of the month
  2010-10-30 18:55 Last workday of the month Chris Maier
@ 2010-10-30 20:19 ` Nick Dokos
  2010-10-31  0:03   ` Chris Maier
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Dokos @ 2010-10-30 20:19 UTC (permalink / raw)
  To: Chris Maier; +Cc: nicholas.dokos, emacs-orgmode

Chris Maier <christopher.maier@gmail.com> wrote:

> I'm trying to come up with a sexp diary entry that shows my payday,
> which is the last weekday of the month, in my Org agenda.  I've tried
> to adapt the example given in the Emacs manual and this is what I came
> up with:
> 
> %%(let ((month (car date))
>         (day (cadr date))
>         (dayname (calendar-day-of-week date)))
>     (or
>      ;; months with 31 days
>      (and (memq month '(1 3 5 7 8 10 12))
>              (or (and (= day 31)
>                       (memq dayname '(1 2 3 4 5)))
>                  (and (memq day '(29 30))
>                       (= dayname 5))))
>      ;; months with 30 days
>      (and (memq month '(4 6 9 11))
>           (or (and (= day 30)
>                    (memq dayname '(1 2 3 4 5)))
>               (and (memq day '(28 29))
>                    (= dayname 5))))
>      ;; February (the weird one)
>      (and (= month 2)
>           (or (and (memq day '(28 29))
>                    (memq dayname '(1 2 3 4 5)))
>               (and (memq day '(26 27 28))
>                    (= dayname 5)))))) Chris' Paycheck Deposited
> 
> It appears to work so far.  However, I'm certain there's got to be a
> more concise way of coding this, but I can't seem to find any
> pre-existing calendar functions that might help.  Am I missing
> something?
> 

This is based on the same idea and example from the manual, but it
precalculates what it needs in order to simplify the decision at
the end:

(let* ((dayname (calendar-day-of-week date))
              (day (calendar-extract-day date))
              (month (calendar-extract-month date))
              (year (calendar-extract-year date))
              (lastday (calendar-last-day-of-month month year))
              (last-two-days-before-last-day (list (- lastday 2) (- lastday 1))))
           (or (and (= day lastday) (memq dayname '(1 2 3 4 5)))
               (and (memq day last-two-days-before-last-day) (= dayname 5)))
              )

Very lightly tested, so use with caution.

> To make this even better, is there some way to consult another file of
> diary entries containing all the holidays at my workplace, so the
> diary entry would show up on the last weekday of the month that is not
> a company holiday?
> 

I'm sure there is - simplest is probably to set a variable in your
.emacs with all the holidays - schedule that with org for Dec. 31 :-) -
but you are on your own for that. I just don't think it's worth it: at
least for me, there are only three holidays during a year that might
interfere with that pay schedule.

HTH,
Nick

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Last workday of the month
  2010-10-30 20:19 ` Nick Dokos
@ 2010-10-31  0:03   ` Chris Maier
  2010-10-31  1:36     ` Chris Maier
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Maier @ 2010-10-31  0:03 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: emacs-orgmode

Where do the functions 'calendar-extract-day',
'calendar-extract-month', 'calendar-extract-year', and
'calendar-last-day-of-the-month' come from?  I was looking for
something like those when I wrote my initial implementation, but I
don't seem to have them (hence the ugliness of the code!)  I'm running
GNU Emacs 23.2 for Mac OS X.  Searching for these functions using `C-h
f` turns up nothing for me.

Thanks for the help,
Chris

On Sat, Oct 30, 2010 at 4:19 PM, Nick Dokos <nicholas.dokos@hp.com> wrote:
> Chris Maier <christopher.maier@gmail.com> wrote:
>
>> I'm trying to come up with a sexp diary entry that shows my payday,
>> which is the last weekday of the month, in my Org agenda.  I've tried
>> to adapt the example given in the Emacs manual and this is what I came
>> up with:
>>
>> %%(let ((month (car date))
>>         (day (cadr date))
>>         (dayname (calendar-day-of-week date)))
>>     (or
>>      ;; months with 31 days
>>      (and (memq month '(1 3 5 7 8 10 12))
>>              (or (and (= day 31)
>>                       (memq dayname '(1 2 3 4 5)))
>>                  (and (memq day '(29 30))
>>                       (= dayname 5))))
>>      ;; months with 30 days
>>      (and (memq month '(4 6 9 11))
>>           (or (and (= day 30)
>>                    (memq dayname '(1 2 3 4 5)))
>>               (and (memq day '(28 29))
>>                    (= dayname 5))))
>>      ;; February (the weird one)
>>      (and (= month 2)
>>           (or (and (memq day '(28 29))
>>                    (memq dayname '(1 2 3 4 5)))
>>               (and (memq day '(26 27 28))
>>                    (= dayname 5)))))) Chris' Paycheck Deposited
>>
>> It appears to work so far.  However, I'm certain there's got to be a
>> more concise way of coding this, but I can't seem to find any
>> pre-existing calendar functions that might help.  Am I missing
>> something?
>>
>
> This is based on the same idea and example from the manual, but it
> precalculates what it needs in order to simplify the decision at
> the end:
>
> (let* ((dayname (calendar-day-of-week date))
>              (day (calendar-extract-day date))
>              (month (calendar-extract-month date))
>              (year (calendar-extract-year date))
>              (lastday (calendar-last-day-of-month month year))
>              (last-two-days-before-last-day (list (- lastday 2) (- lastday 1))))
>           (or (and (= day lastday) (memq dayname '(1 2 3 4 5)))
>               (and (memq day last-two-days-before-last-day) (= dayname 5)))
>              )
>
> Very lightly tested, so use with caution.
>
>> To make this even better, is there some way to consult another file of
>> diary entries containing all the holidays at my workplace, so the
>> diary entry would show up on the last weekday of the month that is not
>> a company holiday?
>>
>
> I'm sure there is - simplest is probably to set a variable in your
> .emacs with all the holidays - schedule that with org for Dec. 31 :-) -
> but you are on your own for that. I just don't think it's worth it: at
> least for me, there are only three holidays during a year that might
> interfere with that pay schedule.
>
> HTH,
> Nick
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Last workday of the month
  2010-10-31  0:03   ` Chris Maier
@ 2010-10-31  1:36     ` Chris Maier
  0 siblings, 0 replies; 4+ messages in thread
From: Chris Maier @ 2010-10-31  1:36 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: emacs-orgmode

Never mind... I think I had something messed up in my initialization
file; they're showing up now.

Chris

On Sat, Oct 30, 2010 at 8:03 PM, Chris Maier
<christopher.maier@gmail.com> wrote:
> Where do the functions 'calendar-extract-day',
> 'calendar-extract-month', 'calendar-extract-year', and
> 'calendar-last-day-of-the-month' come from?  I was looking for
> something like those when I wrote my initial implementation, but I
> don't seem to have them (hence the ugliness of the code!)  I'm running
> GNU Emacs 23.2 for Mac OS X.  Searching for these functions using `C-h
> f` turns up nothing for me.
>
> Thanks for the help,
> Chris
>
> On Sat, Oct 30, 2010 at 4:19 PM, Nick Dokos <nicholas.dokos@hp.com> wrote:
>> Chris Maier <christopher.maier@gmail.com> wrote:
>>
>>> I'm trying to come up with a sexp diary entry that shows my payday,
>>> which is the last weekday of the month, in my Org agenda.  I've tried
>>> to adapt the example given in the Emacs manual and this is what I came
>>> up with:
>>>
>>> %%(let ((month (car date))
>>>         (day (cadr date))
>>>         (dayname (calendar-day-of-week date)))
>>>     (or
>>>      ;; months with 31 days
>>>      (and (memq month '(1 3 5 7 8 10 12))
>>>              (or (and (= day 31)
>>>                       (memq dayname '(1 2 3 4 5)))
>>>                  (and (memq day '(29 30))
>>>                       (= dayname 5))))
>>>      ;; months with 30 days
>>>      (and (memq month '(4 6 9 11))
>>>           (or (and (= day 30)
>>>                    (memq dayname '(1 2 3 4 5)))
>>>               (and (memq day '(28 29))
>>>                    (= dayname 5))))
>>>      ;; February (the weird one)
>>>      (and (= month 2)
>>>           (or (and (memq day '(28 29))
>>>                    (memq dayname '(1 2 3 4 5)))
>>>               (and (memq day '(26 27 28))
>>>                    (= dayname 5)))))) Chris' Paycheck Deposited
>>>
>>> It appears to work so far.  However, I'm certain there's got to be a
>>> more concise way of coding this, but I can't seem to find any
>>> pre-existing calendar functions that might help.  Am I missing
>>> something?
>>>
>>
>> This is based on the same idea and example from the manual, but it
>> precalculates what it needs in order to simplify the decision at
>> the end:
>>
>> (let* ((dayname (calendar-day-of-week date))
>>              (day (calendar-extract-day date))
>>              (month (calendar-extract-month date))
>>              (year (calendar-extract-year date))
>>              (lastday (calendar-last-day-of-month month year))
>>              (last-two-days-before-last-day (list (- lastday 2) (- lastday 1))))
>>           (or (and (= day lastday) (memq dayname '(1 2 3 4 5)))
>>               (and (memq day last-two-days-before-last-day) (= dayname 5)))
>>              )
>>
>> Very lightly tested, so use with caution.
>>
>>> To make this even better, is there some way to consult another file of
>>> diary entries containing all the holidays at my workplace, so the
>>> diary entry would show up on the last weekday of the month that is not
>>> a company holiday?
>>>
>>
>> I'm sure there is - simplest is probably to set a variable in your
>> .emacs with all the holidays - schedule that with org for Dec. 31 :-) -
>> but you are on your own for that. I just don't think it's worth it: at
>> least for me, there are only three holidays during a year that might
>> interfere with that pay schedule.
>>
>> HTH,
>> Nick
>>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-10-31  1:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-30 18:55 Last workday of the month Chris Maier
2010-10-30 20:19 ` Nick Dokos
2010-10-31  0:03   ` Chris Maier
2010-10-31  1:36     ` Chris Maier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).