Splitting functions from onequestionmark-chat

This commit is contained in:
Izwzyzx 2024-10-13 16:43:15 -05:00
commit 0ef7225f13
3 changed files with 78 additions and 0 deletions

11
README.md Normal file
View File

@ -0,0 +1,11 @@
# IzzComLib
Common library for Izwzyzx's Haxe projects.
## Functions
- `randint(x, y)` - Return a random integer between x and y, both inclusive
- `timestamp()` - Returns the current time in 24hr notation, with left-padding (HH:MM)
- `datestamp()` - Returns the current date, formatted to ISO 8601 (YYYY-MM-DD)
- `printDay()` - Returns the name of the current day of the week
- `printMonth()` - Returns the name of the current month
- `printDate()` - Returns the current day of the month, with left padding

8
haxelib.json Normal file
View File

@ -0,0 +1,8 @@
{
"name": "IzzComLib",
"description": "Common library for Izwzyzx's projects",
"license": "Public",
"contributors": ["Izwzyzx"],
"version": "1.0.0",
"releasenote": "Initial release."
}

59
izzcomlib/IzzComLib.hx Normal file
View File

@ -0,0 +1,59 @@
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);
}
}