Skip to content
Back to formatted view

Raw Message

Message-ID: <874nd28sj6.fsf@enricoschumann.net>
Date: 2013-06-13T05:54:21Z
From: Enrico Schumann
Subject: Warning: timeLastNdayInMonth gets Fridays one week off
In-Reply-To: <CA+oJuEGK5FhtTmJDZ1hUtxeH9_8L9Yzd1jo2vi0hjAqZZc6MCg@mail.gmail.com> (Ilya Kipnis's message of "Wed, 12 Jun 2013 12:15:12 -0700")

On Wed, 12 Jun 2013, Ilya Kipnis <ilya.kipnis at gmail.com> writes:

> For those of you looking to find the last Fridays in a month (quarter,
> etc.), I just wanted to issue a warning about using the timeLastNdayInMonth
> function.  For instance, run these lines:
>
>  #dates<-seq(as.Date("2010-01-01"),as.Date("2013-04-02"),by="day") test case
>   friDates<-dates[which(weekdays(dates)=="Friday")]
>   buggedLastMonthlyFridays<-unique(timeLastNdayInMonth(friDates,5)) #gives
> one week after the last friday of the month
>
> and one will notice that the dates are often at the beginning of the next
> month.  This is my fix:
>
> buggedLastMonthlyFridays[which(as.numeric(substr(buggedLastMonthlyFridays,9,10))<20)]<-
>
> as.Date(buggedLastMonthlyFridays[which(as.numeric(substr(buggedLastMonthlyFridays,9,10))<20)])-7
>
> It's not exactly pretty, but I hope this helps someone out there.
>
> -Ilya Kipnis
>

I suppose the 'timeLastNdayInMonth' function is from a package?  Then you
should also contact directly the package's maintainer.



-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net