| 1 |
/* |
| 2 |
* ShiftSelectionList.cpp - TaskJuggler |
| 3 |
* |
| 4 |
* SPDX-FileCopyrightText: 2001, 2002, 2003, 2004 Chris Schlaeger <[email protected]> |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of version 2 of the GNU General Public License as |
| 8 |
* published by the Free Software Foundation. |
| 9 |
* |
| 10 |
* $Id$ |
| 11 |
*/ |
| 12 |
|
| 13 |
// clazy:excludeall=qstring-arg |
| 14 |
#include "ShiftSelectionList.h" |
| 15 |
|
| 16 |
// int |
| 17 |
// ShiftSelectionList::compareItems(QCollection::Item i1, QCollection::Item i2) |
| 18 |
// { |
| 19 |
// ShiftSelection* s1 = static_cast<ShiftSelection*>(i1); |
| 20 |
// ShiftSelection* s2 = static_cast<ShiftSelection*>(i2); |
| 21 |
// |
| 22 |
// return s1->period->compare(*s2->period); |
| 23 |
// } |
| 24 |
|
| 25 |
namespace TJ |
| 26 |
{ |
| 27 |
|
| 28 |
bool |
| 29 |
ShiftSelectionList::isOnShift(const Interval& iv) const |
| 30 |
{ |
| 31 |
/* Check whether any of the defined shift intervals contains the interval |
| 32 |
* 'iv'. If not return true. If it does, check whether the interval 'iv' |
| 33 |
* lies within the specified working hours. */ |
| 34 |
for (ShiftSelectionList::Iterator ssli(*this); ssli.hasNext();) { |
| 35 |
ShiftSelection *s = ssli.next(); |
| 36 |
if (s->getPeriod().contains(iv)) |
| 37 |
return s->getShift()->isOnShift(iv); |
| 38 |
} |
| 39 |
return true; |
| 40 |
} |
| 41 |
|
| 42 |
bool |
| 43 |
ShiftSelectionList::isVacationDay(time_t day) const |
| 44 |
{ |
| 45 |
for (ShiftSelectionList::Iterator ssli(*this); |
| 46 |
ssli.hasNext() && day <= ssli.peekNext()->getPeriod().getEnd();) |
| 47 |
if (ssli.next()->isVacationDay(day)) |
| 48 |
return true; |
| 49 |
return false; |
| 50 |
} |
| 51 |
|
| 52 |
bool |
| 53 |
ShiftSelectionList::insert(ShiftSelection* s) |
| 54 |
{ |
| 55 |
for (ShiftSelectionList::Iterator ssli(*this); ssli.hasNext();) |
| 56 |
if (ssli.next()->getPeriod().overlaps(s->getPeriod())) |
| 57 |
return false; |
| 58 |
append(s); |
| 59 |
return true; |
| 60 |
} |
| 61 |
|
| 62 |
} // namespace TJ |
| 63 |
|
| 64 |
QDebug operator<<(QDebug dbg, const TJ::ShiftSelectionList *s) |
| 65 |
{ |
| 66 |
if (!s) return dbg << "ShiftSelectionList(" << (void*)s << ')'; |
| 67 |
return dbg << *s; |
| 68 |
} |