コード例 #1
0
ファイル: RoughTime.hpp プロジェクト: MindMil/XCSoar
gcc_const
static inline RoughTime
operator+(RoughTime t, RoughTimeDelta delta)
{
  if (!t.IsValid())
    return t;

  int value = t.GetMinuteOfDay() + delta.AsMinutes();
  return RoughTime::FromMinuteOfDayChecked(value);
}
コード例 #2
0
ファイル: DataNode.cpp プロジェクト: kwtskran/XCSoar
void
WritableDataNode::SetAttribute(const TCHAR *name, RoughTime value)
{
  if (!value.IsValid())
    /* no-op */
    return;

  StaticString<8> buffer;
  buffer.UnsafeFormat(_T("%02u:%02u"), value.GetHour(), value.GetMinute());
  SetAttribute(name, buffer);
}
コード例 #3
0
ファイル: RunTimeEntry.cpp プロジェクト: CnZoom/XcSoarPull
static void
Main()
{
  RoughTime value = RoughTime::Invalid();
  const RoughTimeDelta time_zone = RoughTimeDelta::FromMinutes(0);
  if (!TimeEntryDialog(_T("The caption"), value, time_zone, true))
    return;

  if (value.IsValid())
    printf("%02u:%02u\n", value.GetHour(), value.GetMinute());
  else
    printf("invalid\n");
}
コード例 #4
0
ファイル: Task.cpp プロジェクト: Adrien81/XCSoar
gcc_pure
static unsigned
SecondsUntil(unsigned now, RoughTime until)
{
  int d = until.GetMinuteOfDay() * 60 - now;
  if (d < 0)
    d += 24 * 60 * 60;
  return d;
}
コード例 #5
0
ファイル: DigitEntry.cpp プロジェクト: rkohel/XCSoar
void
DigitEntry::SetValue(RoughTime value)
{
    assert(length == 4);
    assert(columns[0].type == Column::Type::HOUR);
    assert(columns[1].type == Column::Type::COLON);
    assert(columns[2].type == Column::Type::DIGIT6);
    assert(columns[3].type == Column::Type::DIGIT);

    if (value.IsValid()) {
        columns[0].value = value.GetHour();
        columns[2].value = value.GetMinute() / 10;
        columns[3].value = value.GetMinute() % 10;
        valid = true;
    } else {
        columns[0].value = 0;
        columns[2].value = 0;
        columns[3].value = 0;
        valid = false;
    }

    Invalidate();
}
コード例 #6
0
ファイル: RoughTime.hpp プロジェクト: MindMil/XCSoar
 constexpr bool HasEnded(RoughTime now) const {
   /* if end is invalid, the time span is open-ended, i.e. it will
      never end */
   return end.IsValid() && now >= end;
 }
コード例 #7
0
ファイル: RoughTime.hpp プロジェクト: MindMil/XCSoar
 constexpr bool HasBegun(RoughTime now) const {
   /* if start is invalid, we assume the time span has always already
      begun */
   return !start.IsValid() || now >= start;
 }
コード例 #8
0
ファイル: RoughTime.hpp プロジェクト: MindMil/XCSoar
 constexpr bool IsDefined() const {
   return start.IsValid() || end.IsValid();
 }
コード例 #9
0
ファイル: TestRoughTime.cpp プロジェクト: MindMil/XCSoar
int main(int argc, char **argv)
{
  plan_tests(77);

  RoughTime a = RoughTime::Invalid();
  ok1(!a.IsValid());

  a = RoughTime(12, 1);
  ok1(a.IsValid());
  ok1(a.GetHour() == 12);
  ok1(a.GetMinute() == 1);
  ok1(a.GetMinuteOfDay() == 12 * 60 + 1);

  /* compare a RoughTime with itself */
  ok1(a == a);
  ok1(!(a != a));
  ok1(a <= a);
  ok1(a >= a);
  ok1(!(a < a));
  ok1(!(a > a));

  /* compare a RoughTime with another one */
  RoughTime b(11, 59);
  ok1(b.IsValid());
  ok1(a != b);
  ok1(!(a == b));
  ok1(!(a <= b));
  ok1(a >= b);
  ok1(!(a < b));
  ok1(a > b);
  ok1(b != a);
  ok1(!(b == a));
  ok1(b <= a);
  ok1(!(b >= a));
  ok1(b < a);
  ok1(!(b > a));

  /* test RoughTimeSpan::IsInside() */
  RoughTimeSpan s = RoughTimeSpan::Invalid();
  ok1(!s.IsDefined());
  ok1(s.IsInside(a));
  ok1(s.IsInside(b));

  s = RoughTimeSpan(RoughTime(12, 0), RoughTime::Invalid());
  ok1(s.IsDefined());
  ok1(s.IsInside(a));
  ok1(!s.IsInside(b));

  s = RoughTimeSpan(RoughTime::Invalid(), RoughTime(12, 0));
  ok1(s.IsDefined());
  ok1(!s.IsInside(a));
  ok1(s.IsInside(b));

  s = RoughTimeSpan(RoughTime(12, 0), RoughTime(12, 1));
  ok1(s.IsDefined());
  ok1(!s.IsInside(a));
  ok1(!s.IsInside(b));

  s = RoughTimeSpan(RoughTime(12, 0), RoughTime(12, 30));
  ok1(s.IsDefined());
  ok1(s.IsInside(a));
  ok1(!s.IsInside(b));

  /* test midnight wraparound */
  a = RoughTime(0, 0);
  b = RoughTime(23, 59);
  ok1(b.IsValid());
  ok1(a != b);
  ok1(!(a == b));
  ok1(!(a <= b));
  ok1(a >= b);
  ok1(!(a < b));
  ok1(a > b);
  ok1(b != a);
  ok1(!(b == a));
  ok1(b <= a);
  ok1(!(b >= a));
  ok1(b < a);
  ok1(!(b > a));

  RoughTime c(22, 0);
  RoughTime d(2, 0);
  s = RoughTimeSpan(RoughTime(23, 0), RoughTime::Invalid());
  ok1(s.IsDefined());
  ok1(s.IsInside(a));
  ok1(s.IsInside(b));
  ok1(!s.IsInside(c));
  ok1(s.IsInside(d));

  s = RoughTimeSpan(RoughTime::Invalid(), RoughTime(1, 0));
  ok1(s.IsDefined());
  ok1(s.IsInside(a));
  ok1(s.IsInside(b));
  ok1(s.IsInside(c));
  ok1(!s.IsInside(d));

  s = RoughTimeSpan(RoughTime(23, 1), RoughTime(0, 30));
  ok1(s.IsDefined());
  ok1(s.IsInside(a));
  ok1(s.IsInside(b));
  ok1(!s.IsInside(c));
  ok1(!s.IsInside(d));

  /* test operator+(RoughTime, RoughTimeDelta) */
  ok1(RoughTime(0, 0) + RoughTimeDelta::FromMinutes(0) == RoughTime(0, 0));
  ok1(RoughTime(0, 0) + RoughTimeDelta::FromMinutes(1) == RoughTime(0, 1));
  ok1(RoughTime(0, 0) + RoughTimeDelta::FromMinutes(60) == RoughTime(1, 0));
  ok1(RoughTime(0, 0) + RoughTimeDelta::FromHours(24) == RoughTime(0, 0));
  ok1(RoughTime(0, 0) + RoughTimeDelta::FromHours(25) == RoughTime(1, 0));

  ok1(RoughTime(0, 0) - RoughTimeDelta::FromMinutes(0) == RoughTime(0, 0));
  ok1(RoughTime(0, 0) - RoughTimeDelta::FromMinutes(1) == RoughTime(23, 59));
  ok1(RoughTime(0, 0) - RoughTimeDelta::FromMinutes(60) == RoughTime(23, 0));
  ok1(RoughTime(0, 0) - RoughTimeDelta::FromHours(24) == RoughTime(0, 0));
  ok1(RoughTime(0, 0) - RoughTimeDelta::FromHours(25) == RoughTime(23, 0));

  return exit_status();
}