View Full Version : Date function contribution

May 19th, 2015, 04:32 PM
I would like to contribute a few date functions that I recently rewrote in Lua. These were originally written in Perl for use in Misterhouse. I use them to determine the day after Thanksgiving and the first Saturday after New Years. This is the time frame that I want our Christmas lights to come on after sunset.

Simple examples:

local datefunctions = require('datefunctions')
local os = require('os')

local year = os.date('%Y')

-- Thanksgiving Day for current year
mm, dd, yy = datefunctions.dayOfMonth('fourth', 'thursday', 11, year)
print('Thanksgiving day in ' .. year .. ' is: ' .. mm .. '/' .. dd)

-- Day after Thanksgiving for current year
mm, dd, yy = datefunctions.dayOfMonth('fourth', 'friday', 11, year)
print('Day after Thanksgiving in ' .. year .. ' is: ' .. mm .. '/' .. dd)

-- First Saturday after New Year's
mm, dd, yy = datefunctions.dayOfMonth('first', 'saturday', 1, year)
print('First Saturday in ' .. year .. ' is: ' .. mm .. '/' .. dd)

-- Is this year a leap year?
print('Is ' .. year .. ' a leap year?', datefunctions.leapYear(year))

Many other functions exist and the functions are fully commented. Some of the functions could probably be done with native date manipulation, but I wanted to go through the exercise to work with Girder and Lua since I'm new to both.

I'm not sure if my approach was right, but I created a sub-directory under /opt/girder/lua named datefunctions to hold the code. It seems to work, but maybe a better name should be applied?

Also, the code could be optimized, but it works well enough. Maybe a cleaner release will follow.

Feedback is welcome.


May 20th, 2015, 07:43 AM
Very cool. I'll look through this soon!

May 26th, 2015, 10:34 AM
Thank you for the contribution. I've placed it in date.extra