示例#1
0
bool DateComponents::setMillisecondsSinceEpochForWeek(double ms) {
  m_type = Invalid;
  if (!std::isfinite(ms))
    return false;
  ms = round(ms);

  m_year = msToYear(ms);
  if (m_year < minimumYear() || m_year > maximumYear())
    return false;

  int yearDay = dayInYear(ms, m_year);
  int offset = offsetTo1stWeekStart(m_year);
  if (yearDay < offset) {
    // The day belongs to the last week of the previous year.
    m_year--;
    if (m_year <= minimumYear())
      return false;
    m_week = maxWeekNumberInYear();
  } else {
    m_week = ((yearDay - offset) / 7) + 1;
    if (m_week > maxWeekNumberInYear()) {
      m_year++;
      m_week = 1;
    }
    if (m_year > maximumYear() ||
        (m_year == maximumYear() && m_week > maximumWeekInMaximumYear))
      return false;
  }
  m_type = Week;
  return true;
}
示例#2
0
bool DateComponents::parseWeek(const String& src,
                               unsigned start,
                               unsigned& end) {
  unsigned index;
  if (!parseYear(src, start, index))
    return false;

  // 4 characters ('-' 'W' digit digit) are needed.
  if (index + 3 >= src.length())
    return false;
  if (src[index] != '-')
    return false;
  ++index;
  if (src[index] != 'W')
    return false;
  ++index;

  int week;
  if (!toInt(src, index, 2, week) || week < minimumWeekNumber ||
      week > maxWeekNumberInYear())
    return false;
  if (m_year == maximumYear() && week > maximumWeekInMaximumYear)
    return false;
  m_week = week;
  end = index + 2;
  m_type = Week;
  return true;
}
示例#3
0
bool DateComponents::parseWeek(const UChar* src, unsigned length, unsigned start, unsigned& end)
{
    ASSERT(src);
    unsigned index;
    if (!parseYear(src, length, start, index))
        return false;

    // 4 characters ('-' 'W' digit digit) are needed.
    if (index + 3 >= length)
        return false;
    if (src[index] != '-')
        return false;
    ++index;
    if (src[index] != 'W')
        return false;
    ++index;

    int week;
    if (!toInt(src, length, index, 2, week) || week < 1 || week > maxWeekNumberInYear())
        return false;
    if (m_year == maximumYear && week > maximumWeekInMaximumYear)
        return false;
    m_week = week;
    end = index + 2;
    m_type = Week;
    return true;
}
示例#4
0
bool DateComponents::setWeek(int year, int weekNumber) {
  m_type = Invalid;
  if (year < minimumYear() || year > maximumYear())
    return false;
  m_year = year;
  if (weekNumber < 1 || weekNumber > maxWeekNumberInYear())
    return false;
  m_week = weekNumber;
  m_type = Week;
  return true;
}