File indexing completed on 2025-03-23 03:32:50
0001 // xlsxnumformatparser.cpp 0002 0003 #include "xlsxnumformatparser_p.h" 0004 0005 #include <QtGlobal> 0006 #include <QString> 0007 0008 QT_BEGIN_NAMESPACE_XLSX 0009 0010 bool NumFormatParser::isDateTime(const QString &formatCode) 0011 { 0012 for (int i = 0; i < formatCode.length(); ++i) { 0013 const QChar &c = formatCode[i]; 0014 0015 switch (c.unicode()) { 0016 case '[': 0017 // [h], [m], [s] are valid format for time 0018 if (i < formatCode.length()-2 && formatCode[i+2] == QLatin1Char(']')) { 0019 const QChar cc = formatCode[i+1].toLower(); 0020 if (cc == QLatin1Char('h') || cc == QLatin1Char('m') || cc == QLatin1Char('s')) 0021 return true; 0022 i+=2; 0023 break; 0024 } else { 0025 // condition or color: don't care, ignore 0026 while (i < formatCode.length() && formatCode[i] != QLatin1Char(']')) 0027 ++i; 0028 break; 0029 } 0030 0031 // quoted plain text block: don't care, ignore 0032 case '"': 0033 while (i < formatCode.length()-1 && formatCode[++i] != QLatin1Char('"')) 0034 ; 0035 break; 0036 0037 // escaped char: don't care, ignore 0038 case '\\': 0039 if (i < formatCode.length() - 1) 0040 ++i; 0041 break; 0042 0043 // date/time can only be positive number, 0044 // so only the first section of the format make sense. 0045 case '#': // this is new an working // https://github.com/QtExcel/QXlsx/issues/190 0046 case ';': 0047 return false; 0048 break; 0049 0050 // days 0051 case 'D': 0052 case 'd': 0053 // years 0054 case 'Y': 0055 case 'y': 0056 // hours 0057 case 'H': 0058 case 'h': 0059 // seconds 0060 case 'S': 0061 case 's': 0062 // minutes or months, depending on context 0063 case 'M': 0064 case 'm': 0065 return true; 0066 0067 default: 0068 break; 0069 } 0070 } 0071 return false; 0072 } 0073 0074 QT_END_NAMESPACE_XLSX