Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
def leap_day(date)
date.month == 2 && date.mday == 29 && Date.leap?(date.year)
def hire_date,4,16) # self.hire_date - Should be a db field, just for temporarily messing around
def current_date # maybe should change to,, ) to get rid of the timestamp since most places don't care about what hour of the day it is
def total_days_current_year, 12, -1).yday()
def years_employed
# If leap day, change calculated startding day to the 28th since DateTime doesn't support invalid dates.
# I prefer not to outright subtract since it's not as deliberate and can be an issue if everything is not properly typecast
# Include the day started as a full day, consider current_date a full day
# The leap day adding logic is not quite complete though. What if the current_date is a leap day, etc.?
year_point = current_date.year - hire_date.year
start_date = leap_day(hire_date) ?, 2, 28) : hire_date # I like recasting the hire day as start_date because then we don't worry about seconds, etc., but should really be addressed in hire_date and start_date
adder_date = + year_point, start_date.month, start_date.mday)
if (adder_date != current_date)
(year_point + (current_date.yday() - adder_date.yday() + 1).to_f/total_days_current_year.to_f).to_f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment