59 lines
1.7 KiB
Haxe
59 lines
1.7 KiB
Haxe
package izzcomlib;
|
|
using StringTools;
|
|
|
|
class IzzComLib {
|
|
/**
|
|
* Return a random integer between x and y, both inclusive.
|
|
* Correctly handles whether parameters are given low-to-high or high-to-low.
|
|
* If parameters are equal, returns x.
|
|
*
|
|
* @param X The lower value.
|
|
* @param Y The upper value.
|
|
*/
|
|
public static function randInt(x, y) {
|
|
if (x < y) {
|
|
return Std.random((y+1)-x)+x;
|
|
} else if (y < x) {
|
|
return Std.random((x+1)-y)+y;
|
|
} else {
|
|
return x;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns the current time in 24hr notation, with left-padding (HH:MM).
|
|
*/
|
|
public static function timestamp() {
|
|
return '${StringTools.lpad(Std.string(Date.now().getHours()), "0", 2)}:${StringTools.lpad(Std.string(Date.now().getMinutes()), "0", 2)}';
|
|
}
|
|
|
|
/**
|
|
* Returns the current date, formatted to ISO 8601 (YYYY-MM-DD).
|
|
*/
|
|
public static function datestamp() {
|
|
return '${Date.now().getFullYear()}-${StringTools.lpad(Std.string(Date.now().getMonth()+1), "0", 2)}-${StringTools.lpad(Std.string(Date.now().getDate()), "0", 2)}';
|
|
}
|
|
|
|
/**
|
|
* Returns the name of the current day of the week.
|
|
*/
|
|
public static function printDay() {
|
|
var weekdays:Array<String> = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
|
|
return weekdays[Date.now().getDay()];
|
|
}
|
|
|
|
/**
|
|
* Returns the name of the current month.
|
|
*/
|
|
public static function printMonth() {
|
|
var months:Array<String> = ["January","February","March","April","May","June","July","August","September","October","November","December"];
|
|
return months[Date.now().getMonth()];
|
|
}
|
|
|
|
/**
|
|
* Returns the current day of the month, with left padding.
|
|
*/
|
|
public static function printDate() {
|
|
return StringTools.lpad(Std.string(Date.now().getDate()), "0", 2);
|
|
}
|
|
} |