/// <summary> /// Constructs a new <b>MyCatDateTime</b> object by copying the current value of the given object. /// </summary> /// <param name="mdt">The <b>MyCatDateTime</b> object to copy.</param> public MyCatDateTime(MyCatDateTime mdt) { year = mdt.Year; month = mdt.Month; day = mdt.Day; hour = mdt.Hour; minute = mdt.Minute; second = mdt.Second; microsecond = 0; millisecond = 0; type = MyCatDbType.DateTime; isNull = false; TimezoneOffset = 0; }
private void SerializeText(MyCatPacket packet, MyCatDateTime value) { string val = String.Empty; val = String.Format("{0:0000}-{1:00}-{2:00}", value.Year, value.Month, value.Day); if (type != MyCatDbType.Date) { val = value.Microsecond > 0 ? String.Format("{0} {1:00}:{2:00}:{3:00}.{4:000000}", val, value.Hour, value.Minute, value.Second, value.Microsecond) : String.Format("{0} {1:00}:{2:00}:{3:00} ", val, value.Hour, value.Minute, value.Second); } packet.WriteStringNoNull("'" + val + "'"); }
/// <summary> /// Enables the contruction of a <b>MyCatDateTime</b> object by parsing a string. /// </summary> public MyCatDateTime(string dateTime) : this(MyCatDateTime.Parse(dateTime)) { }
int IComparable.CompareTo(object obj) { MyCatDateTime otherDate = (MyCatDateTime)obj; if (Year < otherDate.Year) { return(-1); } else if (Year > otherDate.Year) { return(1); } if (Month < otherDate.Month) { return(-1); } else if (Month > otherDate.Month) { return(1); } if (Day < otherDate.Day) { return(-1); } else if (Day > otherDate.Day) { return(1); } if (Hour < otherDate.Hour) { return(-1); } else if (Hour > otherDate.Hour) { return(1); } if (Minute < otherDate.Minute) { return(-1); } else if (Minute > otherDate.Minute) { return(1); } if (Second < otherDate.Second) { return(-1); } else if (Second > otherDate.Second) { return(1); } if (Microsecond < otherDate.Microsecond) { return(-1); } else if (Microsecond > otherDate.Microsecond) { return(1); } return(0); }
static internal MyCatDateTime Parse(string s, Common.DBVersion version) { MyCatDateTime dt = new MyCatDateTime(); return(dt.ParseMyCat(s)); }
static internal MyCatDateTime Parse(string s) { MyCatDateTime dt = new MyCatDateTime(); return(dt.ParseMyCat(s)); }
void IMyCatValue.WriteValue(MyCatPacket packet, bool binary, object value, int length) { MyCatDateTime dtValue; string valueAsString = value as string; if (value is DateTime) { dtValue = new MyCatDateTime(type, (DateTime)value); } else if (valueAsString != null) { dtValue = MyCatDateTime.Parse(valueAsString); } else if (value is MyCatDateTime) { dtValue = (MyCatDateTime)value; } else { throw new MyCatException("Unable to serialize date/time value."); } if (!binary) { SerializeText(packet, dtValue); return; } if (dtValue.Microsecond > 0) { packet.WriteByte(11); } else { packet.WriteByte(7); } packet.WriteInteger(dtValue.Year, 2); packet.WriteByte((byte)dtValue.Month); packet.WriteByte((byte)dtValue.Day); if (type == MyCatDbType.Date) { packet.WriteByte(0); packet.WriteByte(0); packet.WriteByte(0); } else { packet.WriteByte((byte)dtValue.Hour); packet.WriteByte((byte)dtValue.Minute); packet.WriteByte((byte)dtValue.Second); } if (dtValue.Microsecond > 0) { long val = dtValue.Microsecond; for (int x = 0; x < 4; x++) { packet.WriteByte((byte)(val & 0xff)); val >>= 8; } } }