Skip to content

Commit

Permalink
Fix #36 - datenum compatibility extended. (in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson-numerical-software committed Sep 13, 2024
1 parent 947ea44 commit 42bf098
Show file tree
Hide file tree
Showing 16 changed files with 1,270 additions and 470 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- `Resize` - Resize figure property.
- [#36](http://github.com/nelson-lang/nelson/issues/36) `datenum` format compatibility extended.
- [#37](http://github.com/nelson-lang/nelson/issues/37) `datestr` Convert date and time to string format.

### Changed
Expand Down
2 changes: 1 addition & 1 deletion modules/time/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ target_include_directories(
target_link_libraries(
${module_library_name}
nlsCommons
nlsError
nlsError_manager
nlsElementary_mathematics
nlsI18n
nlsInterpreter
Expand Down
10 changes: 5 additions & 5 deletions modules/time/builtin/cpp/Gateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ static const nlsGateway gateway[] = {
{ "sleep", (ptrBuiltin)Nelson::TimeGateway::sleepBuiltin, 1, 1, CPP_BUILTIN_WITH_EVALUATOR },
{ "datevec", (ptrBuiltin)Nelson::TimeGateway::datevecBuiltin, 6, 1 },
{ "calendar", (ptrBuiltin)Nelson::TimeGateway::calendarBuiltin, 1, 2, CPP_BUILTIN },
{ "now", (ptrBuiltin)Nelson::TimeGateway::nowBuiltin, 1, 0 },
{ "clock", (ptrBuiltin)Nelson::TimeGateway::clockBuiltin, 1, 0 },
{ "cputime", (ptrBuiltin)Nelson::TimeGateway::cputimeBuiltin, 1, 0 },
{ "datenum", (ptrBuiltin)Nelson::TimeGateway::datenumBuiltin, 1, 6 },
{ "datestr", (ptrBuiltin)Nelson::TimeGateway::datestrBuiltin, 1, -2 },
{ "now", (ptrBuiltin)Nelson::TimeGateway::nowBuiltin, 1, 0, CPP_BUILTIN },
{ "clock", (ptrBuiltin)Nelson::TimeGateway::clockBuiltin, 1, 0, CPP_BUILTIN },
{ "cputime", (ptrBuiltin)Nelson::TimeGateway::cputimeBuiltin, 1, 0, CPP_BUILTIN },
{ "datenum", (ptrBuiltin)Nelson::TimeGateway::datenumBuiltin, 1, 6, CPP_BUILTIN },
{ "datestr", (ptrBuiltin)Nelson::TimeGateway::datestrBuiltin, 1, -2, CPP_BUILTIN },
{ "time", (ptrBuiltin)Nelson::TimeGateway::timeBuiltin, 1, 0, CPP_BUILTIN },
{ "timeit", (ptrBuiltin)Nelson::TimeGateway::timeitBuiltin, 1, -2, CPP_BUILTIN_WITH_EVALUATOR },
};
Expand Down
431 changes: 239 additions & 192 deletions modules/time/builtin/cpp/datenumBuiltin.cpp

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions modules/time/builtin/cpp/datestrBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ Nelson::TimeGateway::datestrBuiltin(int nLhs, const ArrayOfVector& argIn)
{
nargincheck(argIn, 1, 3);
nargoutcheck(nLhs, 0, 1);
ArrayOfVector retval(nLhs);
ArrayOfVector retval;

bool isValid = argIn[0].isDoubleType(true) && !argIn[0].isSparse() && argIn[0].is2D()
&& argIn[0].isPositive();

bool isValid = argIn[0].isDoubleType(true) && !argIn[0].isSparse() && argIn[0].isPositive()
&& argIn[0].is2D();
if (!isValid) {
Error(_W("Numeric input data must be real."));
if (argIn[0].isStringArray() || argIn[0].isRowVectorCharacterArray()) {
std::wstring v = argIn[0].getContentAsWideString();
Error(v);
} else {
Error(_W("Numeric input data must be real."));
}
}

bool isLocalized = false;
Expand Down
2 changes: 1 addition & 1 deletion modules/time/functions/@char/datestr.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
dateStringIn = varargin{1};
mustBeTextScalar(dateStringIn, 1);
vars = varargin;
vars{1} = string(dateStringIn);
vars{1} = convertCharsToStrings(dateStringIn);
varargout{1} = datestr(vars{:});
end
%=============================================================================
12 changes: 7 additions & 5 deletions modules/time/functions/@string/datestr.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@
varargout{1} = datestr(epochs, 'local');
else
% DateString = datestr(DateStringIn, formatOut)
epochs = datenum(dateStringIn, formatOutOrLocal);
varargout{1} = datestr(epochs);
try
epochs = datenum(dateStringIn);
catch
epochs = datenum(dateStringIn, formatOutOrLocal);
end
varargout{1} = datestr(epochs, formatOutOrLocal);
end
return
end
if nargin == 3
mustBeTextScalar(varargin{2}, 2);
formatOut = convertStringsToChars(varargin{2});

formatOutOrLocal = convertStringsToChars(varargin{3});
if ischar(formatOutOrLocal)
if ~strcmp(formatOutOrLocal, 'local')
Expand All @@ -50,7 +52,7 @@
varargout{1} = datestr(epochs, formatOut, 'local');
elseif (isnumeric(formatOutOrLocal) && isscalar(formatOutOrLocal))
% DateString = datestr(DateStringIn, formatOut, PivotYear)
epochs = datenum(dateStringIn, formatOut, formatOutOrLocal);
epochs = datenum(dateStringIn, formatOutOrLocal);
varargout{1} = datestr(epochs, formatOut);
else
error(_('Third argument must be a numeric scalar.'));
Expand Down
Loading

0 comments on commit 42bf098

Please sign in to comment.