[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: AW: date arithmetic?
- From: Rici Lake <lua@...>
- Date: Tue, 23 Aug 2005 17:26:48 -0500
On 23-Aug-05, at 5:09 PM, steffenj wrote:
Seems to work, but I'm not sure if this is by luck or design.. :)
I think it's by luck. The "official" way of doing it would be to figure
out how much was a day by subtracting one valid date from the next
valid date (although it would work out to 24*60*60 on most OS's), and
then subtracting that from the first day of the next month to get the
last day of the current month.
However, if your way works on all the OS's you care about, go for it :)
Sample code:
do
local oneDay = os.time{year = 2004, month = 2, day = 2}
- os.time{year = 2004, month = 2, day = 1}
function lastDayOfMonth(aDate)
local nextMonth = {year = aDate.year, month = aDate.month + 1, day
= 1}
if nextMonth.month > 12 then
nextMonth.year, nextMonth.month = nextMonth.year + 1, 1
end
return os.date("*t", os.time(nextMonth) - oneDay)
end
end