コード例 #1
0
ファイル: WDate.C プロジェクト: bvanhauwaert/wt
int WDate::parseLongDayName(const std::string& v, unsigned& pos)
{
  std::string remainder = v.substr(pos);

  for (int i = 1; i <= 7; ++i) {
    std::string m = longDayName(i).toUTF8();

    if (remainder.length() >= m.length())
      if (remainder.substr(0, m.length()) == m) {
	pos += m.length();
	return i;
      }
  }

  return -1;
}
コード例 #2
0
QString ExtDate::toString( const QString& format ) const
{
	if ( ! isValid() ) return QString::null;

	//We use the KDE Date format specs.
	//Replace occurences of the following tokens with their
	//corresponding values:
	//
	// %Y The year, including centuries prefix (e.g., "1984")
	// %y The year, excluding centuries prefix (e.g., "84")
	// %n Numerical month value (e.g., "3" for March)
	// %m Numerical month value, two digits (e.g., "03" for March)
	// %e Numerical day value (e.g., "3" on March 3rd)
	// %d Numerical day value, two digits (e.g., "03" on March 3rd)
	// %b Month name, short form (e.g., "Mar" for March)
	// %B Month name, long form (e.g., "March")
	// %a Weekday name, short form (e.g., "Wed" for Wednesday)
	// %A Weekday name, long form (e.g., "Wednesday")

	//All other characters are left as-is.

	QString result( format );

	result.replace( "%Y", QString().sprintf( "%d", year() ) );
	result.replace( "%y", QString().sprintf( "%02d", (year() % 100) ) );
	result.replace( "%n", QString().sprintf( "%d", month() ) );
	result.replace( "%m", QString().sprintf( "%02d", month() ) );
	result.replace( "%e", QString().sprintf( "%d", day() ) );
	result.replace( "%d", QString().sprintf( "%02d", day() ) );
	result.replace( "%b", shortMonthName( month() ) );
	result.replace( "%B", longMonthName( month() ) );
	result.replace( "%a", shortDayName( dayOfWeek() ) );
	result.replace( "%A", longDayName( dayOfWeek() ) );

	return result;
}
コード例 #3
0
ファイル: CDateTime.cpp プロジェクト: teddy-michel/TEngine
CString CDateTime::toString(const CString& format) const
{
    if (isNull())
    {
        return CString();
    }

    CString str;
    bool special = false;
    const unsigned int len = format.getSize();

    for (unsigned int i = 0 ; i < len ; ++i)
    {
        if (format[i] == CChar('%'))
        {
            special = true;
        }
        else if (special)
        {
            switch (format[i].toLatin1())
            {
                default:
                    str += format[i];
                    break;

                case 'a':
                    str += (m_hour < 12 ? "am" : "pm");
                    break;

                case 'A':
                    str += (m_hour < 12 ? "AM" : "PM");
                    break;

                case 'd':

                    if (m_day < 10)
                        str += '0';

                    str += CString::fromNumber(m_day);
                    break;

                case 'D':
                    str += shortDayName(dayOfWeek(m_year, m_month, m_day));
                    break;

                case 'F':
                    str += longMonthName(m_month);
                    break;

                case 'g':

                    if (m_hour == 0)
                    {
                        str += "12";
                    }
                    else if (m_hour < 13)
                    {
                        str += CString::fromNumber(m_hour);
                    }
                    else
                    {
                        str += CString::fromNumber(m_hour - 12);
                    }

                    break;

                case 'G':
                    str += CString::fromNumber(m_hour);
                    break;

                case 'h':

                    if (m_hour == 0)
                    {
                        str += "12";
                    }
                    else if (m_hour < 13)
                    {
                        if (m_hour < 10)
                        {
                            str += '0';
                        }

                        str += CString::fromNumber(m_hour);
                    }
                    else
                    {
                        if (m_hour < 22)
                        {
                            str += '0';
                        }

                        str += CString::fromNumber(m_hour - 12);
                    }

                    break;

                case 'H':

                    if (m_hour < 10)
                    {
                        str += '0';
                    }

                    str += CString::fromNumber(m_hour);

                    break;

                case 'i':

                    if (m_minute < 10)
                    {
                        str += '0';
                    }

                    str += CString::fromNumber(m_minute);

                    break;

                case 'j':
                    str += CString::fromNumber(m_day);
                    break;

                case 'l':
                    str += longDayName(dayOfWeek(m_year, m_month, m_day));
                    break;

                case 'L':
                    str += (isLeapYear(m_year) ? '1' : '0');
                    break;

                case 'm':

                    if (m_month < 10)
                    {
                        str += '0';
                    }

                    str += CString::fromNumber(m_month);

                    break;

                case 'M':
                    str += shortMonthName(m_month);
                    break;

                case 'n':
                    str += CString::fromNumber(m_month);
                    break;

                case 'N':
                    str += dayOfWeek(m_year, m_month, m_day);
                    break;

                case 's':

                    if (m_second < 10)
                    {
                        str += '0';
                    }

                    str += CString::fromNumber(m_second);

                    break;

                case 't':
                    str += CString::fromNumber(daysInMonth(m_month, m_year));
                    break;

                case 'U':
                    str += CString::fromNumber(timestamp(m_year, m_month, m_day, m_hour, m_minute, m_second));
                    break;

                case 'W':
                    str += CString::fromNumber(weekOfYear(m_year, m_month, m_day));
                    break;

                case 'y':

                    if (m_year < 0)
                    {
                        str += CString::fromNumber(m_year);
                    }
                    else
                    {
                        unsigned int tmp = m_year % 100;

                        if (tmp < 10)
                        {
                            str += "0";
                        }

                        str += CString::fromNumber(tmp);
                    }

                    break;

                case 'Y':

                    if (m_year < 0)
                    {
                        str += CString::fromNumber(m_year);
                    }
                    else
                    {
                        unsigned int tmp = m_year % 10000;

                        if (tmp < 10)
                            str += "000";
                        if (tmp < 100)
                            str += "00";
                        if (tmp < 1000)
                            str += "000";

                        str += CString::fromNumber(tmp);
                    }

                    break;

                case 'z':
                    str += dayOfYear(m_year, m_month, m_day);
                    break;
            }

            special = false;
        }
        else
        {
            str += format[i];
        }
    }

    return str;
}
コード例 #4
0
ファイル: WDate.C プロジェクト: bvanhauwaert/wt
bool WDate::writeSpecial(const std::string& f, unsigned&i,
			 std::stringstream& result) const
{
  char buf[30];

  switch (f[i]) {
  case 'd':
    if (f[i + 1] == 'd') {
      if (f[i + 2] == 'd') {
	if (f[i + 3] == 'd') {
	  // 4 d's
	  i += 3;
	  result << longDayName(dayOfWeek()).toUTF8();
	} else {
	  // 3 d's
	  i += 2;
	  result << shortDayName(dayOfWeek()).toUTF8();
	}
      } else {
	// 2 d's
	i += 1;
	result << Utils::pad_itoa(day_, 2, buf);
      }
    } else {
      // 1 d
      result << Utils::itoa(day_, buf);
    }

    return true;
  case 'M':
    if (f[i + 1] == 'M') {
      if (f[i + 2] == 'M') {
	if (f[i + 3] == 'M') {
	  // 4 M's
	  i += 3;
	  result << longMonthName(month_).toUTF8();
	} else {
	  // 3 M's
	  i += 2;
	  result << shortMonthName(month_).toUTF8();
	}
      } else {
	// 2 M's
	i += 1;
	result << Utils::pad_itoa(month_, 2, buf);
      }
    } else {
      // 1 M
      result << Utils::itoa(month_, buf);
    }

    return true;
  case 'y':
    if (f[i + 1] == 'y') {
      if (f[i + 2] == 'y' && f[i + 3] == 'y') {
	// 4 y's
	i += 3;
	result << Utils::itoa(year_, buf);

	return true;
      } else {
	// 2 y's
	i += 1;
	result << Utils::pad_itoa(year_ % 100, 2, buf);

	return true;
      }
    }
  default:
    return false;
  }
}