bids-matlab icon indicating copy to clipboard operation
bids-matlab copied to clipboard

TODO: check if tsvwrite can handle datetime data

Open Remi-Gau opened this issue 2 years ago • 2 comments

Remi-Gau avatar Aug 01 '23 21:08 Remi-Gau

function test_datetime_in_struct()

  if bids.internal.is_octave()
    moxunit_throw_test_skipped_exception('no datetime in Octave');
  end
  
  x = '201401010000';
  acq_time = datetime(x, 'InputFormat', 'yyyyMMddHHmm');
  sub_id = {'foo'};
  patients = struct('sub_id', sub_id, 'acq_time', acq_time);
  
  file = fullfile(tempname(), 'foo.tsv');
  
  bids.util.mkdir(fileparts(file));
  bids.util.tsvwrite(file, patients);

end

Fails:

failure: Error using num2str (line 53)
Input to num2str must be numeric.
  num2str:53 (/usr/local/MATLAB/R2018a/toolbox/matlab/strfun/num2str.p)
  tsvwrite:42 (/home/remi/github/bids/matlab/+bids/+util/tsvwrite.m)
  test_datetime_in_struct:19 (/home/remi/github/bids/matlab/tests/tests_utils/test_tsvwrite.m)

Remi-Gau avatar Aug 02 '23 02:08 Remi-Gau

@gllmflndn I implemented a dirty hack in case the datatime are in table but I am pinging you in case you have better ideas to solve this: at the moment the strategy is to write all dates in a "BIDS" format ('yyyy-MM-dd''T''HH:mm:ss.SSS')

Remi-Gau avatar Aug 02 '23 02:08 Remi-Gau