/* If this is not a one-shot call,
recall this script after the directed delay */
if (fTimerCount > 0.0)
DelayCommand(fTimerCount, PWUMLocationTimer(fTimerCount));
}

void PWUMDateTimer(float fTimerCount=0.0)
{
SetPWUMInt("iPWUMDate", GetOffsetGameDate());
/* If this is not a one-shot call,
recall this script after the directed delay */
if (fTimerCount > 0.0)
DelayCommand(fTimerCount, PWUMDateTimer(fTimerCount));
}

int GetOffsetGameDate(int iOffset=0)
{
/* If a negative number was given then
this variable does not automatically expire. */
if (iOffset < 0)
return -1;
else
/* Otherwise, return the number of days from "0/0/0".
Which means if a zero was sent, the variable
expires at the end of the current game day.*/
{
// Get the game calendar date
int iYear=GetCalendarYear();
int iMonth=GetCalendarMonth();
int iDay=GetCalendarDay();
// Add to the appropriate integer until iOffset == 0
while (iOffset > 335)
{
iYear++;
iOffset -= 336;
}
while (iOffset > 27)
{
iMonth++;
iOffset -= 28;
}
while (iOffset > 0)
{
iDay++;
iOffset--;
}
/* Now, if we have more than 28 days, roll the
month, and if we have more than 12 months,
roll the year - due to the way the year, month,
and days were added above, it should be impossible
to have more than 24 months or 56 days. */
if (iDay > 28)
{
iDay -= 28;
iMonth++;
}
if (iMonth > 12)
{
iMonth -= 12;
iYear++;
}
return iYear*336 + iMonth*28 + iDay;
}
}

void SetPWUMCalendar(int iOffsetDate)
{
int iToday=GetOffsetGameDate(0);
/* Only set the date if the saved date is after
the start of the module. */
if (iOffsetDate > iToday)
{
// Get "zero" date
int iYear=0;
int iMonth=0;
int iDay=0;
// Add to the appropriate integer until iOffset == 0
while (iOffsetDate > 335)
{
iYear++;
iOffsetDate -= 336;
}
while (iOffsetDate > 27)
{
iMonth++;
iOffsetDate -= 28;
}
while (iOffsetDate > 1)
{
iDay++;
iOffsetDate--;
}
/* Now, if we have more than 28 days, roll the
month, and if we have more than 12 months,
roll the year - due to the way the year, month,
and days were added above, it should be impossible
to have more than 24 months or 56 days. */
if (iDay > 28)
{
iDay -= 28;
iMonth++;
}
if (iMonth > 12)
{
iMonth -= 12;
iYear++;
}
SetCalendar(iYear, iMonth, iDay);
}
}