1 /* vi: set sw=4 ts=4: 2 * 3 * Copyright (C) 2001 - 2012, 2018 Christian Hohnstaedt. 4 * 5 * All rights reserved. 6 */ 7 8 #ifndef __ASN1TIME_H 9 #define __ASN1TIME_H 10 11 #include <QString> 12 #include <QDateTime> 13 #include <openssl/asn1.h> 14 15 #define SECS_PER_MINUTE (60) 16 #define SECS_PER_HOUR (SECS_PER_MINUTE *60) 17 #define SECS_PER_DAY (SECS_PER_HOUR*24) 18 19 #define MSECS_PER_MINUTE (SECS_PER_MINUTE*1000) 20 #define MSECS_PER_HOUR (SECS_PER_HOUR*1000) 21 22 class a1time : public QDateTime 23 { 24 private: 25 ASN1_TIME *atime; 26 int from_asn1(const ASN1_TIME *a); 27 int set_asn1(const QString &str, int type); 28 29 public: 30 a1time(); 31 a1time(const QDateTime &a); 32 a1time(const ASN1_TIME *a); 33 a1time(const a1time &a); 34 a1time(const QString &plain); 35 a1time &operator = (const a1time &a); 36 ~a1time(); 37 a1time &set(const ASN1_TIME *a); 38 int fromPlain(const QString &plain); 39 a1time &setUndefined(); 40 bool isUndefined() const; 41 QString toString(QString fmt, Qt::TimeSpec spec = Qt::UTC) const; 42 QString toPretty() const; 43 QString toPrettyGMT() const; 44 QString toPlain(const QString &fmt = QString()) const; 45 QString toPlainUTC() const; 46 QString toSortable() const; 47 QString toFancy() const; 48 QString isoLocalDate() const; 49 ASN1_TIME *get(); 50 ASN1_TIME *get_utc(); 51 static QDateTime now(int delta = 0); 52 QByteArray i2d(); 53 void d2i(QByteArray &ba); 54 qint64 age() const; 55 }; 56 57 #endif 58