-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1533 from CBATeam/get-week-day
Add CBA_fnc_weekDay
- Loading branch information
Showing
4 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "script_component.hpp" | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_weekDay | ||
Description: | ||
Calculates date's day of the week using a modified Rata Die method with fractional years. | ||
Parameters: | ||
_date - Date of [year, month, day]. <ARRAY> | ||
Returns: | ||
Day of the week (0: Sunday, 6: Saturday, -1: invalid) <NUMBER> | ||
Examples: | ||
(begin example) | ||
[systemTimeUTC] call CBA_fnc_weekDay; | ||
[date] call CBA_fnc_weekDay; | ||
[[2022, 2, 16]] call CBA_fnc_weekDay; | ||
(end) | ||
Author: | ||
Jonpas | ||
---------------------------------------------------------------------------- */ | ||
|
||
params [["_date", [0, 0, 0], [[]], [3, 4, 5, 6, 7]]]; | ||
|
||
// Keep only year, month, day if longer date format is given | ||
// Hours and minutes must be given as 0 for dateToNumber to work correctly for this use-case | ||
_date = [_date select 0, _date select 1, _date select 2, 0, 0]; | ||
|
||
private _yearBefore = ((_date select 0) - 1) max 0; | ||
private _leapYears = floor (_yearBefore / 4); | ||
private _normalYears = _yearBefore - _leapYears; | ||
private _days = _normalYears + (_leapYears * (366 / 365)) + dateToNumber _date; | ||
|
||
(round (_days / (1 / 365))) mod 7 // return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "script_component.hpp" | ||
SCRIPT(test_common); | ||
|
||
// execVM "\x\cba\addons\common\test_common.sqf"; | ||
|
||
private ["_funcName", "_result"]; | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
_funcName = "CBA_fnc_weekDay"; | ||
LOG("Testing " + _funcName); | ||
|
||
TEST_DEFINED("CBA_fnc_weekDay",""); | ||
|
||
_result = [] call CBA_fnc_weekDay; | ||
TEST_TRUE(_result == -1,_funcName); // invalid | ||
|
||
_result = [[0, 0, 0]] call CBA_fnc_weekDay; | ||
TEST_TRUE(_result == -1,_funcName); // invalid | ||
|
||
_result = [[2022, 1, 1]] call CBA_fnc_weekDay; | ||
TEST_TRUE(_result == 6,_funcName); // Saturday | ||
|
||
_result = [[2022, 2, 16]] call CBA_fnc_weekDay; | ||
TEST_TRUE(_result == 3,_funcName); // Wednesday | ||
|
||
// date format [year, month, day, hour, minute] | ||
_result = [[2022, 2, 17, 11, 56]] call CBA_fnc_weekDay; | ||
TEST_TRUE(_result == 4,_funcName); // Thursday | ||
|
||
// systemTime format [year, month, day, hour, minute, second, millisecond] | ||
_result = [[2022, 2, 18, 11, 56, 24, 126]] call CBA_fnc_weekDay; | ||
TEST_TRUE(_result == 5,_funcName); // Friday |