context: // Copyright (c) 2004-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
  //
  // MySQL Connector/NET is licensed under the terms of the GPLv2
  // <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most 
  // MySQL Connectors. There are special exceptions to the terms and 
  // conditions of the GPLv2 as it is applied to this software, see the 
  // FLOSS License Exception
  // <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
  //
  // This program is free software; you can redistribute it and/or modify 
  // it under the terms of the GNU General Public License as published 
  // by the Free Software Foundation; version 2 of the License.
  //
  // This program is distributed in the hope that it will be useful, but 
  // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
  // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
  // for more details.
  //
  // You should have received a copy of the GNU General Public License along 
  // with this program; if not, write to the Free Software Foundation, Inc., 
  // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  
  using System;
  using System.Data;
  using System.IO;
  using MySql.Data.MySqlClient;
  using System.Globalization;
  
  
  namespace MySql.Data.Types
  {
  
    /// <summary>
    /// 
    /// </summary>
    public partial struct MySqlDateTime : IMySqlValue, IComparable
    {
      private bool isNull;
      private MySqlDbType type;
      private int year, month, day, hour, minute, second;
      private int millisecond;
      public int TimezoneOffset;
  
      /// <summary>
      /// Constructs a new <b>MySqlDateTime</b> object by setting the individual time properties to
      /// the given values.
      /// </summary>
      /// <param name="year">The year to use.</param>
      /// <param name="month">The month to use.</param>
      /// <param name="day">The day to use.</param>
      /// <param name="hour">The hour to use.</param>
      /// <param name="minute">The minute to use.</param>
      /// <param name="second">The second to use.</param>
      /// <param name="millisecond">The millisecond to use.</param>
      public MySqlDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
        : this(MySqlDbType.DateTime, year, month, day, hour, minute, second, millisecond)
      {
      }
  
      /// <summary>
      /// Constructs a new <b>MySqlDateTime</b> object by using values from the given <see cref="DateTime"/> object.
      /// </summary>
      /// <param name="dt">The <see cref="DateTime"/> object to copy.</param>
      public MySqlDateTime(DateTime dt)
        : this(MySqlDbType.DateTime, dt)
      {
      }
  
      /// <summary>
      /// Constructs a new <b>MySqlDateTime</b> object by copying the current value of the given object.
      /// </summary>
      /// <param name="mdt">The <b>MySqlDateTime</b> object to copy.</param>
      public MySqlDateTime(MySqlDateTime mdt)
      {
        year = mdt.Year;
        month = mdt.Month;
        day = mdt.Day;
        hour = mdt.Hour;
        minute = mdt.Minute;
        second = mdt.Second;
        millisecond = 0;
        type = MySqlDbType.DateTime;
        isNull = false;
        TimezoneOffset = 0;
      }
  
      /// <summary>
      /// Enables the contruction of a <b>MySqlDateTime</b> object by parsing a string.
      /// </summary>
      public MySqlDateTime(string dateTime)
        : this(MySqlDateTime.Parse(dateTime))
      {
      }
  
      internal MySqlDateTime(MySqlDbType type, int year, int month, int day, int hour, int minute,
        int second, int millisecond)
      {
        this.isNull = false;
        this.type = type;
        this.year = year;
        this.month = month;
        this.day = day;
        this.hour = hour;
        this.minute = minute;
        this.second = second;
        this.millisecond = millisecond > 0 ? millisecond : 0;
        this.TimezoneOffset = 0;
      }
  
      internal MySqlDateTime(MySqlDbType type, bool isNull)
        : this(type, 0, 0, 0, 0, 0, 0, 0)
      {
        this.isNull = isNull;
      }
  
      internal MySqlDateTime(MySqlDbType type, DateTime val)
        : this(type, 0, 0, 0, 0, 0, 0, 0)
      {
        this.isNull = false;
        year = val.Year;
        month = val.Month;
        day = val.Day;
        hour = val.Hour;
        minute = val.Minute;
        second = val.Second;
        millisecond = val.Millisecond;
      }
  
      #region Properties
  
      /// <summary>
      /// Indicates if this object contains a value that can be represented as a DateTime
      /// </summary>
      public bool IsValidDateTime
      {
        get
        {
          return year != 0 && month != 0 && day != 0;
        }
      }
  
      /// <summary>Returns the year portion of this datetime</summary>
      public int Year
      {
        get { return year; }
        set { year = value; }
      }
  
      /// <summary>Returns the month portion of this datetime</summary>
      public int Month
      {
        get { return month; }
        set { month = value; }
      }
  
      /// <summary>Returns the day portion of this datetime</summary>
      public int Day
      {
        get { return day; }
        set { day = value; }
      }
  
      /// <summary>Returns the hour portion of this datetime</summary>
      public int Hour
      {
        get { return hour; }
        set { hour = value; }
      }
  
      /// <summary>Returns the minute portion of this datetime</summary>
      public int Minute
      {
        get { return minute; }
        set { minute = value; }
      }
  
      /// <summary>Returns the second portion of this datetime</summary>
      public int Second
      {
        get { return second; }
        set { second = value; }
      }
  
      /// <summary>
      /// Retrieves the millisecond value of this object.
      /// </summary>
      public int Millisecond
      {
        get { return millisecond; }
        set { millisecond = value; }
      }
  
      #endregion
  
      #region IMySqlValue Members
  
      /// <summary>
      /// Returns true if this datetime object has a null value
      /// </summary>
      public bool IsNull
      {
        get { return isNull; }
      }
  
      MySqlDbType IMySqlValue.MySqlDbType
      {
        get { return type; }
      }
  
      object IMySqlValue.Value
      {
        get { return GetDateTime(); }
      }
  
      /// <summary>
      /// Retrieves the value of this <see cref="MySqlDateTime"/> as a DateTime object.
      /// </summary>
      public DateTime Value
      {
        get { return GetDateTime(); }
      }
  
      Type IMySqlValue.SystemType
      {
  
gt:       get { return typeof(DateTime); }