| 1 | function [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: |
|---|
| 26 | |
|---|
| 27 | hourSplit = regexp(time,'(\d{1,2}):(\d{2})\s(\w{2})','tokens'); |
|---|
| 28 | hours = hourSplit{1}{1}; |
|---|
| 29 | minutes = hourSplit{1}{2}; |
|---|
| 30 | antePost = hourSplit{1}{3}; |
|---|
| 31 | if 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 |
|---|
| 35 | else %if AM |
|---|
| 36 | if strcmp(hours, '12') |
|---|
| 37 | hours = '00'; |
|---|
| 38 | end |
|---|
| 39 | end |
|---|
| 40 | if length(hours)==1 |
|---|
| 41 | hours = ['0' hours]; |
|---|
| 42 | end |
|---|
| 43 | hours = char(hours); |
|---|
| 44 | minutes = char(minutes); |
|---|