forked from arnodelorme/mffmatlabio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mff_encodetime.m
58 lines (52 loc) · 1.93 KB
/
mff_encodetime.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
% mff_encodetime - encode EGI time format from Matlab time format
%
% Usage:
% timeout = mff_encodetime(timein);
%
% Input:
% timein - EGI time format (numerical)
%
% Output:
% timeout - EGI string format time
%
% Example:
% timeValOut = mff_decodetime('2009-04-16T21:52:47.893250-08:00')
% mff_encodetime(timeValOut,'08:00')
%
% timeValOut = mff_decodetime('2009-04-16T21:52:47.893750-08:00')
% mff_encodetime(timeValOut,'08:00') % issue here
% This file is part of mffmatlabio.
%
% mffmatlabio 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.
%
% mffmatlabio 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 mffmatlabio. If not, see <https://www.gnu.org/licenses/>.
function timeValOut = mff_encodetime(timeVal, timeZone)
% remove GMT part
microSec = 0.000000000011525116860866546630859375000;
% estimate error
tmp = datestr(timeVal, 'yyyy-mm-ddTHH:MM:SS.FFF');
remain = timeVal-mff_decodetime([tmp '000']);
if remain < 0
tmp = datestr(timeVal-microSec*1000, 'yyyy-mm-ddTHH:MM:SS.FFF');
remain = timeVal-mff_decodetime([tmp '000']);
if remain < 0
error('Negative microseconds');
end
end
timeValOut = [ tmp sprintf('%.3d', round(remain/microSec/10)*10) timeZone ];
% old code
% millisec = 0.000000000011525116860866546630859375000;
%
% tmp = timeVal/millisec;
% remain = (tmp-floor(tmp))*1000;
%
% timeValOut = [ datestr(timeVal, 'yyyy-mm-ddTHH:MM:SS.FFF') sprintf('%.3d', round(remain,-1)) '-' timeZone ];