Skip to content
Permalink
Browse files

Add constructor variant to QgsInterval which uses QgsUnitTypes::Tempo…

…ralUnit
  • Loading branch information
nyalldawson committed Mar 12, 2020
1 parent 555d1ef commit 2959276c8fa90a61734538c44725a7697fd7aed1
@@ -42,6 +42,11 @@ Default constructor for QgsInterval. Creates an invalid interval.
Constructor for QgsInterval.

:param seconds: duration of interval in seconds
%End

QgsInterval( double duration, QgsUnitTypes::TemporalUnit unit );
%Docstring
Constructor for QgsInterval, using the specified ``duration`` and ``units``.
%End

double years() const;
@@ -33,6 +33,13 @@ QgsInterval::QgsInterval( double seconds )
, mValid( true )
{ }

QgsInterval::QgsInterval( double duration, QgsUnitTypes::TemporalUnit unit )
: mSeconds( duration * QgsUnitTypes::fromUnitToUnitFactor( unit, QgsUnitTypes::TemporalSeconds ) )
, mValid( true )
{

}

bool QgsInterval::operator==( QgsInterval other ) const
{
if ( !mValid && !other.mValid )
@@ -26,6 +26,7 @@

#include "qgis_sip.h"
#include "qgis_core.h"
#include "qgsunittypes.h"

class QString;

@@ -66,6 +67,11 @@ class CORE_EXPORT QgsInterval
*/
QgsInterval( double seconds );

/**
* Constructor for QgsInterval, using the specified \a duration and \a units.
*/
QgsInterval( double duration, QgsUnitTypes::TemporalUnit unit );

/**
* Returns the interval duration in years (based on an average year length)
* \see setYears()
@@ -12,7 +12,7 @@

import qgis # NOQA

from qgis.core import QgsInterval
from qgis.core import QgsInterval, QgsUnitTypes
from qgis.testing import unittest


@@ -37,6 +37,11 @@ def testIntervalConstructor(self):
self.assertTrue(i.isValid())
self.assertEqual(i.seconds(), 56)

# constructor with unit type
i = QgsInterval(56, QgsUnitTypes.TemporalMilliseconds)
self.assertTrue(i.isValid())
self.assertEqual(i.seconds(), 56000)

def testSettersGetters(self):
# setters and getters
i = QgsInterval()

0 comments on commit 2959276

Please sign in to comment.
You can’t perform that action at this time.