Created
September 11, 2009 16:05
-
-
Save tncbbthositg/185384 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using PayrollYear = System.Int32; | |
using PayperiodNumber = System.Int32; | |
namespace TAS.SQL_DAL | |
{ | |
public class PayrollYearInfo | |
{ | |
// i used the year 1950 because this is the furthest back I could find information | |
// about federal payperiods. the first day of the first pay period in 1950 was | |
// 1950/01/08. | |
private static Dictionary<PayrollYear, PayrollYearInfo> yearCache = new Dictionary<PayrollYear, PayrollYearInfo>(); | |
private static DateTime genesis = new DateTime(1950, 1, 8); | |
private static int surplusDaysAtGenesis = 7; | |
private Dictionary<PayperiodNumber, PayPeriodInfo> periodCache = new Dictionary<PayperiodNumber, PayPeriodInfo>(); | |
private PayrollYearInfo previousYear; | |
private PayrollYearInfo nextYear; | |
private PayrollYearInfo(PayrollYear year) | |
{ | |
PayrollYear = year; | |
} | |
public static PayrollYearInfo GetPayrollYearInfo(PayrollYear year) | |
{ | |
lock (yearCache) | |
{ | |
if (!yearCache.ContainsKey(year)) | |
yearCache[year] = new PayrollYearInfo(year); | |
} | |
return yearCache[year]; | |
} | |
public int PayrollYear { get; private set; } | |
public PayrollYearInfo Previous | |
{ | |
get | |
{ | |
if (previousYear == null) | |
previousYear = GetPayrollYearInfo(PayrollYear - 1); | |
return previousYear; | |
} | |
} | |
public PayrollYearInfo Next | |
{ | |
get | |
{ | |
if (nextYear == null) | |
nextYear = GetPayrollYearInfo(PayrollYear + 1); | |
return nextYear; | |
} | |
} | |
public int YearsSinceGenesis { get { return PayrollYear - genesis.Year; } } | |
public int SurplusDays { get { return YearsSinceGenesis + LeapDaysSinceGenesis + surplusDaysAtGenesis; } } | |
public int AdditionalPayPeriods { get { return SurplusDays / 14; } } | |
public int PayPeriods { get { return Next.ElapsedPayPeriods - ElapsedPayPeriods; } } | |
public int DaysSinceGenesis { get { return ElapsedPayPeriods * 14; } } | |
public DateTime FirstDayOfPayrollYear { get { return genesis.AddDays(DaysSinceGenesis); } } | |
public int LeapDaysSinceGenesis | |
{ | |
get | |
{ | |
return (YearsSinceGenesis + 2) / 4 - (YearsSinceGenesis + 50) / 100 + (YearsSinceGenesis + 350) / 400; | |
} | |
} | |
public int ElapsedPayPeriods | |
{ | |
get | |
{ | |
if (PayrollYear <= 1950) return 0; | |
return 26 * YearsSinceGenesis + Previous.AdditionalPayPeriods; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment