Parse() static private method

static private Parse ( string s ) : MySqlDateTime
s string
return MySqlDateTime
Example #1
0
        void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object value, int length)
        {
            string        text = value as string;
            MySqlDateTime value2;

            if (value is DateTime)
            {
                value2 = new MySqlDateTime(this.type, (DateTime)value);
            }
            else if (text != null)
            {
                value2 = MySqlDateTime.Parse(text);
            }
            else
            {
                if (!(value is MySqlDateTime))
                {
                    throw new MySqlException("Unable to serialize date/time value.");
                }
                value2 = (MySqlDateTime)value;
            }
            if (!binary)
            {
                this.SerializeText(packet, value2);
                return;
            }
            if (value2.Millisecond > 0)
            {
                packet.WriteByte(11);
            }
            else
            {
                packet.WriteByte(7);
            }
            packet.WriteInteger((long)value2.Year, 2);
            packet.WriteByte((byte)value2.Month);
            packet.WriteByte((byte)value2.Day);
            if (this.type == MySqlDbType.Date)
            {
                packet.WriteByte(0);
                packet.WriteByte(0);
                packet.WriteByte(0);
            }
            else
            {
                packet.WriteByte((byte)value2.Hour);
                packet.WriteByte((byte)value2.Minute);
                packet.WriteByte((byte)value2.Second);
            }
            if (value2.Millisecond > 0)
            {
                long num = (long)((value2.Millisecond < 1000) ? (value2.Millisecond * 1000) : value2.Millisecond);
                for (int i = 0; i < 4; i++)
                {
                    packet.WriteByte((byte)(num & 255L));
                    num >>= 8;
                }
            }
        }
        void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object value, int length)
        {
            MySqlDateTime dtValue;

            string valueAsString = value as string;

            if (value is DateTime)
            {
                dtValue = new MySqlDateTime(_type, (DateTime)value);
            }
            else if (valueAsString != null)
            {
                dtValue = MySqlDateTime.Parse(valueAsString);
            }
            else if (value is MySqlDateTime)
            {
                dtValue = (MySqlDateTime)value;
            }
            else
            {
                throw new MySqlException("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 == MySqlDbType.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;
                }
            }
        }
Example #3
0
 /// <summary>
 /// Enables the contruction of a <b>MySqlDateTime</b> object by parsing a string.
 /// </summary>
 public MySqlDateTime(string dateTime)
     : this(MySqlDateTime.Parse(dateTime))
 {
 }
Example #4
0
 public MySqlDateTime(string s) : this(MySqlDateTime.Parse(s))
 {
 }
Example #5
0
 public MySqlDateTime(string dateTime)
 {
     this = new MySqlDateTime(MySqlDateTime.Parse(dateTime));
 }