Date and Time API

Add Another Mod

 

Mod File number (downloads) -

MD5

Type -

Tools

Server / Client -

Server Side

Mod Sub Cat -

N/A

Mod Version -

1.0

Total Views -

Mod screen shot -

Date and Time API

Mod PK3

PK3 MD5

Mod External Info -

Game Type -

MOHAA

 

 

Mod Creator -

Sor

 

 

 

 

Mod Status -

Fully working no errors

 

Team -

 

Theme -

Rating

Extra Credits -

 

Iinstall / info

I wrote a date and time API a long time ago. I've spent the last four hours rewriting it. The implementation is based on that of the DateTime struct in .NET

Download and unrar the script and place it in your main/reborn/ folder. If it does not exist, create it.
You could also package it in a pk3 as long as the path remains the same.

In your script, you have to initialize the API before you can use it:

waitexec reborn/datetime.scr;

At this point, you can access the API through level.DateTime.

local.boolean = waitthread level.DateTime.IsLeapYear local.year;

Determines whether the specified year, or the current year if none specified, is a leap year.

local.days= waitthread level.DateTime.GetDaysInMonth local.month local.year;

Determines how many days the specified month has in the specified year, or the current year if none specified.

local.year = waitthread level.DateTime.GetYear;

Gets the current year as an integer [1, 9999].

local.month = waitthread level.DateTime.GetMonth;

Gets the current month as an integer [1, 12].

local.day = waitthread level.DateTime.GetDay;

Gets the current day of the month as an integer [1, 31]

local.weekday = waitthread level.DateTime.GetDayOfWeek;

Gets the current day of the week as an integer [0, 6] where Sunday is 0, Monday is 1 etc...

local.day = waitthread level.DateTime.GetDayOfYear;

Gets the current day of the year as an integer [1, 366]

local.hour = waitthread level.DateTime.GetHour;

Gets the current hour of the current day as an integer [0, 23]

local.minute = waitthread level.DateTime.GetMinute;

Gets the current minute of the current hour as an integer [0, 59]

local.second = waitthread level.DateTime.GetSecond;

Gets the current second of the current minute as an integer [0, 59]

local.offset = waitthread level.DateTime.GetTimeZone;

Gets the local time zone offset [-12, 14]

local.days = waitthread level.DateTime.GetDayNames;

Gets a zero-indexed array of names of each week day where index 0 is Sunday, index 1 is Monday etc...
The value returned by a call to GetDayOfWeek() corresponds to the index in this array.

local.months = waitthread level.DateTime.GetMonthNames;

Gets a one-indexed array of names of each month where index 1 is January, index 2 is February etc...
The value returned by a call to GetMonth() corresponds to the index in this array.

local.dateTime = waitthread level.DateTime.Create local.second local.minute local.hour local.day local.month local.year local.timeZoneOffset;

Creates a new DateTime instance of an instant in time. If no time zone offset is specified, the offset of the local time zone will be used.

local.dateTime = waitthread level.DateTime.Now;

Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.

local.dateTime = waitthread level.DateTime.UtcNow;

Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC+0).

local.dateTime2 = waitthread level.DateTime.ToTimeZone local.dateTime local.timeZoneOffset;

Gets a DateTime object representing the value of the specified DateTime object in the specified time zone.

local.result = waitthread level.DateTime.Compare local.dateTime local.dateTime2;

Compares two DateTime objects. This function returns 1 if the first is more recent than the second, -1 if the second is more recent or 0 if they are equal.

The DateTime instance is simply a Listener object that represents an instant in time, expressed as a date and a time of day.
The actual date and time are stored as a number of seconds in a day and a number of days since year 0001 AD. This makes
implementating operations such as addition and subtraction way simpler. Only counting the seconds would have been even
better but the integer value would overflow. This mean that the object has no public properties for the year, month etc... .
Luckily, the interface of the object does provide this functionality:

local.dateTime = local.dateTime waitthread local.dateTime.AddYears local.years;

Gets a new DateTime instance that adds the specified number of years to the value of this instance.

local.dateTime = local.dateTime waitthread local.dateTime.AddMonths local.months;

Gets a new DateTime instance that adds the specified number of months to the value of this instance.

local.dateTime = local.dateTime waitthread local.dateTime.AddDays local.days;

Gets a new DateTime instance that adds the specified number of days to the value of this instance.

local.dateTime = local.dateTime waitthread local.dateTime.AddHours local.hours;

Gets a new DateTime instance that adds the specified number of hours to the value of this instance.

local.dateTime = local.dateTime waitthread local.dateTime.AddMinutes local.minutes;

Gets a new DateTime instance that adds the specified number of minutes to the value of this instance.

local.dateTime = local.dateTime waitthread local.dateTime.AddSeconds local.seconds;

Gets a new DateTime instance that adds the specified number of seconds to the value of this instance.

local.result = local.dateTime waitthread local.dateTime.CompareTo local.dateTime2;

Compares two DateTime objects. This function returns 1 if the first is more recent than the second, -1 if the second is more recent or 0 if they are equal.

local.year = local.dateTime waitthread local.dateTime.GetYear;

Gets the year component of the date represented by this instance as an integer [1, 9999].

local.month = local.dateTime waitthread local.dateTime.GetMonth;

Gets the month component of the date represented by this instance as an integer [1, 12].

local.day = local.dateTime waitthread local.dateTime.GetDay;

Gets the day of the month represented by this instance as an integer [1, 31]

local.weekday = local.dateTime waitthread local.dateTime.GetDayOfWeek;

Gets the day of the week represented by this instance as an integer [0, 6] where Sunday is 0, Monday is 1 etc...

local.day = local.dateTime waitthread local.dateTime.GetDayOfYear;

Gets the day of the year represented by this instance as an integer [1, 366]

local.hour = local.dateTime waitthread local.dateTime.GetHour;

Gets the hour component of the date represented by this instance as an integer [0, 23]

local.minute = local.dateTime waitthread local.dateTime.GetMinute;

Gets the minute component of the date represented by this instance as an integer [0, 59]

local.second = local.dateTime waitthread local.dateTime.GetSecond;

Gets the hour component of the date represented by this instance as an integer [0, 59]

local.offset = local.dateTime waitthread local.dateTime.GetTimeZone;

Gets the time zone offset of the date represented by this instance as an integer [-12, 14]

local.localTime = local.dateTime waitthread local.dateTime.ToLocalTime;

Converts the value of this DateTime object to local time.

local.utcTime = local.dateTime waitthread local.dateTime.ToUniversalTime;

Converts the value of this DateTime object to Coordinated Universal Time (UTC+0).

println(local.dateTime waitthread local.dateTime.ToTimeString);

Gets the time component and time zone offset of the date represented by this instance as a string.

println(local.dateTime waitthread local.dateTime.ToDateString);

Gets the date component of the date represented by this instance as a string.

println(local.dateTime waitthread local.dateTime.ToString);

Gets the date represented by this instance as a string.

Finally, if you're done with a DateTime object, you will have to dispose it like so.

local.dateTime waitthread local.dateTime.Dispose;

Beware that exceptions will be thrown if invalid input is given to any function. Currently two exceptions are thrown,
ArgumentNullException and InvalidArgumentException. Handle them as follows:

try {
local.dateTime = waitthread level.DateTime.create 0 0 0 18 5 2015;
} catch {
InvalidArgumentException:
println("Could not create DateTime object.");
}

try {
local.year = local.dateTime waitthread local.dateTime.GetYear;
} catch {
ArgumentNullException:
println("DateTime object is null.");
}

Video