initial commit of Gregorian/IFC date conversion tools and unit tests
This commit is contained in:
53
IFCmonths.m
Normal file
53
IFCmonths.m
Normal file
@@ -0,0 +1,53 @@
|
||||
function [nMonths, Days, leaped, yeared] = IFCmonths(Days, Year)
|
||||
arguments (Input)
|
||||
Days (:, 1) uint16
|
||||
Year (:, 1) uint16
|
||||
end
|
||||
arguments (Output)
|
||||
nMonths (:, 1) uint8
|
||||
Days (:, 1) uint8
|
||||
leaped (:, 1) logical
|
||||
yeared (:, 1) logical
|
||||
end
|
||||
|
||||
% intialize output to first month
|
||||
nMonths = ones(size(Days));
|
||||
|
||||
% initialize output saying a leap day happened to false
|
||||
leaped = false(size(Days));
|
||||
|
||||
% initialize output saying a year day happened to false
|
||||
yeared = false(size(Days));
|
||||
|
||||
% check if it's a leap year
|
||||
leap = isLeap(Year);
|
||||
|
||||
% while more days than 1 month, add months to nMonths
|
||||
excess = Days > 28;
|
||||
while any(excess)
|
||||
% Subtract 28 days and add one month
|
||||
Days(excess) = Days(excess) - 28;
|
||||
nMonths(excess) = nMonths(excess) + 1;
|
||||
|
||||
% Find dates which are reaching the leap day (if it exists)
|
||||
leaping = (leap & nMonths == 7);
|
||||
% subtract leap day before proceeding to add another month
|
||||
Days(leaping) = Days(leaping) - 1;
|
||||
% Set leap day output to true
|
||||
leaped(leaping) = true;
|
||||
% Set the month to 14 (no month) if there are no days left
|
||||
% meaning the last day is the leap day
|
||||
% (which is not in any month)
|
||||
noneLeft = ~Days;
|
||||
nMonths(noneLeft) = 14;
|
||||
% continue subtracting days and adding months as needed
|
||||
|
||||
% find excess days remaining for next iteration
|
||||
excess = Days > 28;
|
||||
end
|
||||
|
||||
% check for if a year day occured
|
||||
yearing = (nMonths == 14 & Days == 1);
|
||||
yeared(yearing) = true; % Year day achieved, set flag
|
||||
Days(yearing) = 0; % decrement Days since year day was taken
|
||||
end
|
||||
Reference in New Issue
Block a user