File indexing completed on 2024-11-24 04:42:24

0001 /*
0002  *  repetition.h  -  represents a sub-repetition: interval and count
0003  *  This file is part of kalarmcalendar library, which provides access to KAlarm
0004  *  calendar data.
0005  *  Program:  kalarm
0006  *  SPDX-FileCopyrightText: 2009-2022 David Jarvie <djarvie@kde.org>
0007  *
0008  *  SPDX-License-Identifier: LGPL-2.0-or-later
0009  */
0010 
0011 #pragma once
0012 
0013 #include "kalarmcal_export.h"
0014 
0015 #include <KCalendarCore/Duration>
0016 
0017 namespace KAlarmCal
0018 {
0019 
0020 class KADateTime;
0021 
0022 /**
0023  * @short Represents a sub-repetition, defined by interval and repeat count.
0024  *
0025  *  The Repetition class represents a sub-repetition, storing its interval
0026  *  and repeat count. The repeat count is the number of repetitions after
0027  *  the first occurrence.
0028  *
0029  *  @author David Jarvie <djarvie@kde.org>
0030  */
0031 class KALARMCAL_EXPORT Repetition
0032 {
0033 public:
0034     /** Default constructor.
0035      *  Initialises to no repetition.
0036      */
0037     Repetition();
0038 
0039     /** Constructor.
0040      *  Initialises with the specified @p interval and @p count.
0041      */
0042     Repetition(const KCalendarCore::Duration& interval, int count);
0043 
0044     Repetition(const Repetition& other);
0045 
0046     ~Repetition();
0047 
0048     Repetition& operator=(const Repetition& other);
0049 
0050     /** Initialises the instance with the specified @p interval and @p count. */
0051     void set(const KCalendarCore::Duration& interval, int count);
0052     /** Sets the @p interval. The repetition count is unchanged unless
0053      *  The repetition count is set to zero if @p interval is zero; otherwise
0054      *  the repetition count is unchanged.
0055      */
0056     void set(const KCalendarCore::Duration& interval);
0057 
0058     /** Returns whether a repetition is defined.
0059      *  @return true if a repetition is defined, false if not.
0060      */
0061     operator bool() const;
0062 
0063     /** Returns whether no repetition is defined.
0064      *  @return false if a repetition is defined, true if not.
0065      */
0066     bool operator!() const
0067     {
0068         return !operator bool();
0069     }
0070 
0071     bool operator==(const Repetition& r) const;
0072     bool operator!=(const Repetition& r) const
0073     {
0074         return !operator==(r);
0075     }
0076 
0077     /** Return the number of repetitions. */
0078     int count() const;
0079 
0080     /** Return the interval between repetitions. */
0081     KCalendarCore::Duration interval() const;
0082 
0083     /** Return the overall duration of the repetition. */
0084     KCalendarCore::Duration duration() const;
0085 
0086     /** Return the overall duration of a specified number of repetitions.
0087      *  @param count the number of repetitions to find the duration of.
0088      */
0089     KCalendarCore::Duration duration(int count) const;
0090 
0091     /** Check whether the repetition interval is in terms of days (as opposed to minutes). */
0092     bool isDaily() const;
0093 
0094     /** Return the repetition interval in terms of days.
0095      *  If necessary, the interval is rounded down to a whole number of days.
0096      */
0097     int intervalDays() const;
0098 
0099     /** Return the repetition interval in terms of minutes.
0100      *  If necessary, the interval is rounded down to a whole number of minutes.
0101      */
0102     int intervalMinutes() const;
0103 
0104     /** Return the repetition interval in terms of seconds. */
0105     int intervalSeconds() const;
0106 
0107     /** Find the repetition count for the next repetition after a specified time.
0108      *  @param from         repetition start time, which should not be a date-only value
0109      *  @param preDateTime  time after which the desired repetition occurs
0110      */
0111     int nextRepeatCount(const KADateTime& from, const KADateTime& preDateTime) const;
0112 
0113     /** Find the repetition count for the last repetition before a specified time.
0114      *  @param from           repetition start time, which should not be a date-only value
0115      *  @param afterDateTime  time after which the desired repetition occurs
0116      */
0117     int previousRepeatCount(const KADateTime& from, const KADateTime& afterDateTime) const;
0118 
0119 private:
0120     //@cond PRIVATE
0121     class Private;
0122     Private* const d;
0123     //@endcond
0124 };
0125 
0126 } // namespace KAlarmCal
0127 
0128 // vim: et sw=4: