wumu
2023-06-14 e0873308a615c7e8f78fe653fd3bb2ecf4739501
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// xlsxnumformatparser.cpp
 
#include "xlsxnumformatparser_p.h"
 
#include <QtGlobal>
#include <QString>
 
QT_BEGIN_NAMESPACE_XLSX
 
bool NumFormatParser::isDateTime(const QString &formatCode)
{
    for (int i = 0; i < formatCode.length(); ++i) {
        const QChar &c = formatCode[i];
 
        switch (c.unicode()) {
        case '[':
            // [h], [m], [s] are valid format for time
            if (i < formatCode.length()-2 && formatCode[i+2] == QLatin1Char(']')) {
                const QChar cc = formatCode[i+1].toLower();
                if (cc == QLatin1Char('h') || cc == QLatin1Char('m') || cc == QLatin1Char('s'))
                    return true;
                i+=2;
                break;
            } else {
                // condition or color: don't care, ignore
                while (i < formatCode.length() && formatCode[i] != QLatin1Char(']'))
                    ++i;
                break;
            }
 
        // quoted plain text block: don't care, ignore
        case '"':
            while (i < formatCode.length()-1 && formatCode[++i] != QLatin1Char('"'))
                ;
            break;
 
        // escaped char: don't care, ignore
        case '\\':
            if (i < formatCode.length() - 1)
                ++i;
            break;
 
        // date/time can only be positive number,
        // so only the first section of the format make sense.
        case '#': // this is new an working // https://github.com/QtExcel/QXlsx/issues/190
        case ';':
            return false;
            break;
 
        // days
        case 'D':
        case 'd':
        // years
        case 'Y':
        case 'y':
        // hours
        case 'H':
        case 'h':
        // seconds
        case 'S':
        case 's':
        // minutes or months, depending on context
        case 'M':
        case 'm':
            return true;
 
        default:
            break;
        }
    }
    return false;
}
 
QT_END_NAMESPACE_XLSX