Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

PString PTime::AsString ( TimeFormat  formatCode = RFC1123,
int  zone = Local 
) const

Convert the time to a string representation.

Parameters:
formatCode  Standard format for time.
zone  Time zone for the time.

Definition at line 427 of file ptime.cxx.

References DayMonthYear, GetDateOrder(), GetDateSeparator(), GetTimeAMPM(), GetTimeSeparator(), Local, LongDate, LongDateTime, LongISO8601, LongTime, MediumDate, MediumDateTime, MonthDayYear, RFC1123, ShortDate, ShortDateTime, ShortISO8601, ShortTime, and YearMonthDay.

Referenced by AsString(), PTrace::Begin(), PSystemLog::Output(), and PrintOn().

{ 
  if (format >= NumTimeStrings)
    return "Invalid format : " + AsString("yyyy-MM-dd T hh:mm:ss Z");

  switch (format) {
    case RFC1123 :
      return AsString("wwwe, dd MMME yyyy hh:mm:ss z", zone);
    case ShortISO8601 :
      return AsString("yyyyMMddThhmmssZ");
    case LongISO8601 :
      return AsString("yyyy-MM-dd T hh:mm:ss Z");
    default :
      break;
  }

  PString fmt, dsep;

  PString tsep = GetTimeSeparator();
  BOOL is12hour = GetTimeAMPM();

  switch (format ) {
    case LongDateTime :
    case LongTime :
    case MediumDateTime :
    case ShortDateTime :
    case ShortTime :
      if (!is12hour)
        fmt = "h";

      fmt += "h" + tsep + "mm";

      switch (format) {
        case LongDateTime :
        case LongTime :
          fmt += tsep + "ss";

        default :
          break;
      }

      if (is12hour)
        fmt += "a";
      break;

    default :
      break;
  }

  switch (format ) {
    case LongDateTime :
    case MediumDateTime :
    case ShortDateTime :
      fmt += ' ';
      break;

    default :
      break;
  }

  switch (format ) {
    case LongDateTime :
    case LongDate :
      fmt += "wwww ";
      switch (GetDateOrder()) {
        case MonthDayYear :
          fmt += "MMMM d, yyyy";
          break;
        case DayMonthYear :
          fmt += "d MMMM yyyy";
          break;
        case YearMonthDay :
          fmt += "yyyy MMMM d";
      }
      break;

    case MediumDateTime :
    case MediumDate :
      fmt += "www ";
      switch (GetDateOrder()) {
        case MonthDayYear :
          fmt += "MMM d, yy";
          break;
        case DayMonthYear :
          fmt += "d MMM yy";
          break;
        case YearMonthDay :
          fmt += "yy MMM d";
      }
      break;

    case ShortDateTime :
    case ShortDate :
      dsep = GetDateSeparator();
      switch (GetDateOrder()) {
        case MonthDayYear :
          fmt += "MM" + dsep + "dd" + dsep + "yy";
          break;
        case DayMonthYear :
          fmt += "dd" + dsep + "MM" + dsep + "yy";
          break;
        case YearMonthDay :
          fmt += "yy" + dsep + "MM" + dsep + "dd";
      }
      break;

    default :
      break;
  }

  if (zone != Local)
    fmt += " z";

  return AsString(fmt, zone);
}


Generated by  Doxygen 1.6.0   Back to index