andre@1: /**************************************************************************** andre@1: ** Copyright (c) 2013-2014 Debao Zhang andre@1: ** All right reserved. andre@1: ** andre@1: ** Permission is hereby granted, free of charge, to any person obtaining andre@1: ** a copy of this software and associated documentation files (the andre@1: ** "Software"), to deal in the Software without restriction, including andre@1: ** without limitation the rights to use, copy, modify, merge, publish, andre@1: ** distribute, sublicense, and/or sell copies of the Software, and to andre@1: ** permit persons to whom the Software is furnished to do so, subject to andre@1: ** the following conditions: andre@1: ** andre@1: ** The above copyright notice and this permission notice shall be andre@1: ** included in all copies or substantial portions of the Software. andre@1: ** andre@1: ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, andre@1: ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF andre@1: ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND andre@1: ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE andre@1: ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION andre@1: ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION andre@1: ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. andre@1: ** andre@1: ****************************************************************************/ andre@1: #include "xlsxnumformatparser_p.h" andre@1: andre@1: #include andre@1: andre@1: namespace QXlsx { andre@1: andre@1: bool NumFormatParser::isDateTime(const QString &formatCode) andre@1: { andre@1: for (int i = 0; i < formatCode.length(); ++i) { andre@1: const QChar &c = formatCode[i]; andre@1: andre@1: switch (c.unicode()) { andre@1: case '[': andre@1: // [h], [m], [s] are valid format for time andre@1: if (i < formatCode.length()-2 && formatCode[i+2] == QLatin1Char(']')) { andre@1: const QChar cc = formatCode[i+1].toLower(); andre@1: if (cc == QLatin1Char('h') || cc == QLatin1Char('m') || cc == QLatin1Char('s')) andre@1: return true; andre@1: i+=2; andre@1: break; andre@1: } else { andre@1: // condition or color: don't care, ignore andre@1: while (i < formatCode.length() && formatCode[i] != QLatin1Char(']')) andre@1: ++i; andre@1: break; andre@1: } andre@1: andre@1: // quoted plain text block: don't care, ignore andre@1: case '"': andre@1: while (i < formatCode.length()-1 && formatCode[++i] != QLatin1Char('"')) andre@1: ; andre@1: break; andre@1: andre@1: // escaped char: don't care, ignore andre@1: case '\\': andre@1: if (i < formatCode.length() - 1) andre@1: ++i; andre@1: break; andre@1: andre@1: // date/time can only be positive number, andre@1: // so only the first section of the format make sense. andre@1: case ';': andre@1: return false; andre@1: break; andre@1: andre@1: // days andre@1: case 'D': andre@1: case 'd': andre@1: // years andre@1: case 'Y': andre@1: case 'y': andre@1: // hours andre@1: case 'H': andre@1: case 'h': andre@1: // seconds andre@1: case 'S': andre@1: case 's': andre@1: // minutes or months, depending on context andre@1: case 'M': andre@1: case 'm': andre@1: return true; andre@1: andre@1: default: andre@1: break; andre@1: } andre@1: } andre@1: return false; andre@1: } andre@1: andre@1: } // namespace QXlsx