commit 0ef7225f13d5a0348481871faa891ea913da1daf Author: Izwzyzx <184772711+Izwzyzx@users.noreply.github.com> Date: Sun Oct 13 16:43:15 2024 -0500 Splitting functions from onequestionmark-chat diff --git a/README.md b/README.md new file mode 100644 index 0000000..1acae1f --- /dev/null +++ b/README.md @@ -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 \ No newline at end of file diff --git a/haxelib.json b/haxelib.json new file mode 100644 index 0000000..bf925e4 --- /dev/null +++ b/haxelib.json @@ -0,0 +1,8 @@ +{ + "name": "IzzComLib", + "description": "Common library for Izwzyzx's projects", + "license": "Public", + "contributors": ["Izwzyzx"], + "version": "1.0.0", + "releasenote": "Initial release." + } \ No newline at end of file diff --git a/izzcomlib/IzzComLib.hx b/izzcomlib/IzzComLib.hx new file mode 100644 index 0000000..73be3fc --- /dev/null +++ b/izzcomlib/IzzComLib.hx @@ -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 = ["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 = ["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); + } +} \ No newline at end of file