File indexing completed on 2024-05-12 17:16:23

0001 /*
0002  * Port for usage with qt-framework and development for kdesvn
0003  * Copyright (C) 2005-2009 by Rajko Albrecht (ral@alwins-world.de)
0004  * http://kdesvn.alwins-world.de
0005  */
0006 /*
0007  * ====================================================================
0008  * Copyright (c) 2002-2005 The RapidSvn Group.  All rights reserved.
0009  * dev@rapidsvn.tigris.org
0010  *
0011  * This library is free software; you can redistribute it and/or
0012  * modify it under the terms of the GNU Lesser General Public
0013  * License as published by the Free Software Foundation; either
0014  * version 2.1 of the License, or (at your option) any later version.
0015  *
0016  * This library is distributed in the hope that it will be useful,
0017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0019  * Lesser General Public License for more details.
0020  *
0021  * You should have received a copy of the GNU Lesser General Public
0022  * License along with this library (in the file LGPL.txt); if not,
0023  * write to the Free Software Foundation, Inc., 51 Franklin St,
0024  * Fifth Floor, Boston, MA  02110-1301  USA
0025  *
0026  * This software consists of voluntary contributions made by many
0027  * individuals.  For exact contribution history, see the revision
0028  * history and logs, available at http://rapidsvn.tigris.org/.
0029  * ====================================================================
0030  */
0031 
0032 #include "datetime.h"
0033 
0034 // apr
0035 #include <apr_date.h>
0036 
0037 namespace svn
0038 {
0039 DateTime::DateTime()
0040     : m_time()
0041 {
0042 }
0043 
0044 DateTime::DateTime(const apr_time_t time)
0045     : m_time()
0046 {
0047     setAprTime(time);
0048 }
0049 
0050 DateTime::DateTime(const QDateTime &dt)
0051     : m_time(dt)
0052 {
0053 }
0054 
0055 DateTime::DateTime(const QString &dt)
0056 {
0057     SetRFC822Date(dt.toUtf8().constData());
0058 }
0059 
0060 apr_time_t
0061 DateTime::GetAPRTimeT() const
0062 {
0063     apr_time_t aTime;
0064     apr_time_ansi_put(&aTime, m_time.toSecsSinceEpoch());
0065     return aTime;
0066 }
0067 
0068 bool
0069 DateTime::SetRFC822Date(const char *date)
0070 {
0071     apr_time_t aTime = apr_date_parse_rfc(date);
0072     setAprTime(aTime);
0073     return IsValid();
0074 }
0075 
0076 void DateTime::setAprTime(apr_time_t aTime)
0077 {
0078     if (aTime < 0) {
0079         m_time = QDateTime();
0080     } else {
0081         m_time = QDateTime::fromMSecsSinceEpoch(aTime / 1000);  // microsec -> millisec
0082     }
0083     m_time.setTimeSpec(Qt::LocalTime);
0084 }
0085 
0086 QString DateTime::toString(const QString &format)const
0087 {
0088     return m_time.toString(format);
0089 }
0090 
0091 QString DateTime::toString(Qt::DateFormat f) const
0092 {
0093     return m_time.toString(f);
0094 }
0095 } // namespace svn