added util function

This commit is contained in:
Martin Rotter 2021-05-27 08:25:31 +02:00
parent 0f737a1328
commit ade6268eb1
3 changed files with 10 additions and 0 deletions

View File

@ -91,6 +91,7 @@ Note that `MessageObject` attributes which can be synchronized back to service a
|---|---|---|
| `String hostname()` | `utils.hostname()` | Returns name of your PC. |
| `String fromXmlToJson(String)` | `utils.fromXmlToJson('<h1>hello</h1>')` | Converts `XML` string into `JSON`. |
| `Date parseDateTime(String)` | `utils.parseDateTime('2020-02-24T08:00:00')` | Converts textual date/time representation into proper `Date` object. |
## Examples
Accept only messages from "Bob" while also marking them important.

View File

@ -3,6 +3,7 @@
#include "core/filterutils.h"
#include "definitions/definitions.h"
#include "miscellaneous/textfactory.h"
#include <QDomDocument>
#include <QHostInfo>
@ -70,3 +71,7 @@ QString FilterUtils::fromXmlToJson(const QString& xml) const {
return QSL("{\"%1\": %2}").arg(xml_doc.documentElement().tagName(),
json);
}
QDateTime FilterUtils::parseDateTime(const QString& dat) const {
return TextFactory::parseDateTime(dat);
}

View File

@ -3,6 +3,7 @@
#ifndef FILTERUTILS_H
#define FILTERUTILS_H
#include <QDateTime>
#include <QDomElement>
#include <QObject>
@ -18,6 +19,9 @@ class FilterUtils : public QObject {
// Converts XML -> JSON or returns empty string if failed.
Q_INVOKABLE QString fromXmlToJson(const QString& xml) const;
// Parses string into date/time object.
Q_INVOKABLE QDateTime parseDateTime(const QString& dat) const;
};
#endif // FILTERUTILS_H