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 c5ddc77
Show file tree
Hide file tree
Showing 13 changed files with 1,255 additions and 464 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
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
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 c5ddc77

Please sign in to comment.