## Copyright (C) 2026 Andreas Bertsatos <abertsatos@biol.uoa.gr>
##
## This file is part of the datatypes package for GNU Octave.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.

################################################################################
##                 ** Create and convert 'datetime' type **                   ##
################################################################################
##                             Available Methods                              ##
##                                                                            ##
## 'datetime'         'dispstrings'      'cellstr'          'char'            ##
## 'ymd'              'hms'              'year'             'quarter'         ##
## 'month'            'week'             'day'              'hour'            ##
## 'minute'           'second'           'timeofday'        'tzoffset'        ##
##                                                                            ##
################################################################################

## Test 'datetime' constructor
%!test  # scalar components broadcast against a non-scalar component
%! d = datetime (2020, 1, [1; 2], 12, 30, 0);
%! assert_equal (size (d), [2, 1]);
%! assert_equal (cellstr (d), {'01-Jan-2020 12:30:00'; '02-Jan-2020 12:30:00'});

################################################################################
##                          ** Query Operations **                            ##
################################################################################
##                             Available Methods                              ##
##                                                                            ##
## 'isbetween'        'iscolumn'         'isdst'            'isempty'         ##
## 'isequal'          'isequaln'         'isfinite'         'isinf'           ##
## 'ismatrix'         'ismember'         'isnat'            'isregular'       ##
## 'isrow'            'isscalar'         'issorted'         'issortedrows'    ##
## 'isvector'         'isweekend'                                             ##
##                                                                            ##
################################################################################

## Test 'ismissing'
%!test  # without indicator, NaT elements are missing
%! d = datetime (2020, 1, [1; 2; 3]);
%! d(2) = datetime (NaN, NaN, NaN);
%! assert_equal (ismissing (d), [false; true; false]);
%!test  # scalar datetime indicator
%! d = datetime (2020, 1, [1; 2; 3]);
%! assert_equal (ismissing (d, datetime (2020, 1, 3)), [false; false; true]);
%!test  # multi-element datetime indicator matches any listed value
%! d = datetime (2020, 1, [1; 2; 3]);
%! ind = datetime (2020, 1, [1; 3]);
%! assert_equal (ismissing (d, ind), [true; false; true]);

%!error <datetime.ismissing: too many input arguments.> ...
%! ismissing (datetime (2020, 1, 1), datetime (2020, 1, 1), 3)
%!error <datetime.ismissing: INDICATOR must be a 'datetime' array.> ...
%! ismissing (datetime (2020, 1, 1), 5)
%!error <datetime.ismissing: INDICATOR must be a vector.> ...
%! ismissing (datetime (2020, 1, 1), datetime (2020, 1, ones (2, 2)))
