/// <summary> /// Ported from format_datetime /// </summary> public string FormatDateTime(DateTime when, FormatTypeEnum formatType = FormatTypeEnum.FMT_PRINTED, string format = null) { if (formatType == FormatTypeEnum.FMT_WRITTEN) { return(WrittenDateTimeIO.Format(when)); } else if (formatType == FormatTypeEnum.FMT_CUSTOM && format != null) { DateTimeIO dateIO; if (TempDateTimeIO.TryGetValue(format, out dateIO)) { return(dateIO.Format(when)); } else { dateIO = new DateTimeIO(format, false); TempDateTimeIO.Add(format, dateIO); return(dateIO.Format(when)); } } else if (formatType == FormatTypeEnum.FMT_PRINTED) { return(PrintedDateTimeIO.Format(when)); } throw new InvalidOperationException("formatter"); }
public void TimesInitialize() { if (!IsInitialized) { InputDateTimeIO = new DateTimeIO("%Y/%m/%d %H:%M:%S", true); TimelogDateTimeIO = new DateTimeIO("%m/%d/%Y %H:%M:%S", true); WrittenDateTimeIO = new DateTimeIO("%Y/%m/%d %H:%M:%S", false); WrittenDateIO = new DateIO("%Y/%m/%d", false); PrintedDateTimeIO = new DateTimeIO("%y-%b-%d %H:%M:%S", false); PrintedDateIO = new DateIO("%y-%b-%d", false); Readers.Add(new DateIO("%m/%d", true)); Readers.Add(new DateIO("%Y/%m/%d", true)); Readers.Add(new DateIO("%Y/%m", true)); Readers.Add(new DateIO("%y/%m/%d", true)); Readers.Add(new DateIO("%Y-%m-%d", true)); IsInitialized = true; } }