root/trunk/ampmto24.m

Revision 131, 1.5 KB (checked in by fboyer, 7 years ago)

MOD: GPL to LGPL License

  • Property svn:executable set to *
Line 
1function [hours minutes] = ampmto24(time)
2% Convert an AM/PM time into 24h time
3%
4% [HOURS MINUTES] = AMPMTO24(TIME)
5%
6% time:    time in .csv format                                     [string]
7% hours:   extracted hours                                            [int]
8% minutes: extracted minutes                                          [int]
9
10% Copyright 2006-2007 INRIA
11%
12% This file is part of WellReader
13%
14% WellReader is free software: you can redistribute it and/or modify
15% it under the terms of the GNU Lesser General Public License as published by
16% the Free Software Foundation, either version 3 of the License, or
17% (at your option) any later version.
18%
19% WellReader is distributed in the hope that it will be useful,
20% but WITHOUT ANY WARRANTY; without even the implied warranty of
21% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22% GNU Lesser General Public License for more details.
23%
24% You should have received a copy of the GNU Lesser General Public License
25% along with WellReader.  If not, see <http://www.gnu.org/licenses/>.
26
27hourSplit = regexp(time,'(\d{1,2}):(\d{2})\s(\w{2})','tokens');
28hours = hourSplit{1}{1};
29minutes = hourSplit{1}{2};
30antePost = hourSplit{1}{3};
31if strcmp(antePost, 'PM')
32    if ~strcmp(hours, '12') %if time is 12:10 PM it actually means 12:10 24h
33        hours = num2str(str2double(hours) + 12);
34    end
35else %if AM
36    if strcmp(hours, '12')
37        hours = '00';
38    end
39end
40if length(hours)==1
41    hours = ['0' hours];
42end
43hours = char(hours);
44minutes = char(minutes);
Note: See TracBrowser for help on using the browser.