File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change 22
22
elseif length(val ) == 0
23
23
valstr = ' []' ;
24
24
end
25
+ valstr = strrep(valstr ,' -Inf' , ' null' );
25
26
valstr = strrep(valstr , ' Inf' , ' null' );
26
27
valstr = strrep(valstr , ' NaN' , ' null' );
27
28
elseif ischar(val )
39
40
else
40
41
valstr = ' false' ;
41
42
end
43
+ elseif isdatetime(val )
44
+ valstr = m2json(convertDate(val ));
45
+ elseif isstring(val )
46
+ fh = ifel(isscalar(val ),@char ,@cellstr );
47
+ valstr = m2json(fh(val ));
42
48
else
43
49
valstr = ' ' ; % wtf is it?
50
+ warning(" Failed to m2json encode class of type: %s" ,class(val ));
44
51
end
Original file line number Diff line number Diff line change 1
- function convertedDate = convertDate(date )
2
- date.Format = ' yyyy-MM-dd HH:mm:ss' ;
3
- convertedDate = char(date );
4
- end
1
+ function output = convertDate(date )
2
+ date = convertToDateTime(date );
3
+ if isDate(date )
4
+ format = " yyyy-mm-dd" ;
5
+ else
6
+ format = " yyyy-mm-dd HH:MM:ss" ;
7
+ end
8
+ output = string(date , format );
9
+ end
10
+
11
+ function dt = convertToDateTime(input )
12
+ if isdatetime(input )
13
+ return
14
+ elseif isnumeric(input )
15
+ % Assume input is a datenum
16
+ dt = datetime(input , ' ConvertFrom' , ' datenum' );
17
+ elseif ischar(input ) || isstring(input )
18
+ % Assume input is a date string
19
+ dt = datetime(input );
20
+ else
21
+ error(' Unsupported date type' );
22
+ end
23
+ end
24
+
25
+ function tf = isDate(dt )
26
+ tf = all([hour(dt ), minute(dt ), second(dt )] == 0 );
27
+ end
You can’t perform that action at this time.
0 commit comments