xlsxnumformatparser.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // xlsxnumformatparser.cpp
  2. #include "xlsxnumformatparser_p.h"
  3. #include <QtGlobal>
  4. #include <QString>
  5. QT_BEGIN_NAMESPACE_XLSX
  6. bool NumFormatParser::isDateTime(const QString &formatCode)
  7. {
  8. for (int i = 0; i < formatCode.length(); ++i) {
  9. const QChar &c = formatCode[i];
  10. switch (c.unicode()) {
  11. case '[':
  12. // [h], [m], [s] are valid format for time
  13. if (i < formatCode.length()-2 && formatCode[i+2] == QLatin1Char(']')) {
  14. const QChar cc = formatCode[i+1].toLower();
  15. if (cc == QLatin1Char('h') || cc == QLatin1Char('m') || cc == QLatin1Char('s'))
  16. return true;
  17. i+=2;
  18. break;
  19. } else {
  20. // condition or color: don't care, ignore
  21. while (i < formatCode.length() && formatCode[i] != QLatin1Char(']'))
  22. ++i;
  23. break;
  24. }
  25. // quoted plain text block: don't care, ignore
  26. case '"':
  27. while (i < formatCode.length()-1 && formatCode[++i] != QLatin1Char('"'))
  28. ;
  29. break;
  30. // escaped char: don't care, ignore
  31. case '\\':
  32. if (i < formatCode.length() - 1)
  33. ++i;
  34. break;
  35. // date/time can only be positive number,
  36. // so only the first section of the format make sense.
  37. case ';':
  38. return false;
  39. break;
  40. // days
  41. case 'D':
  42. case 'd':
  43. // years
  44. case 'Y':
  45. case 'y':
  46. // hours
  47. case 'H':
  48. case 'h':
  49. // seconds
  50. case 'S':
  51. case 's':
  52. // minutes or months, depending on context
  53. case 'M':
  54. case 'm':
  55. return true;
  56. default:
  57. break;
  58. }
  59. }
  60. return false;
  61. }
  62. QT_END_NAMESPACE_XLSX