Пример #1
0
        public override int CompareTo(object obj)
        {
            ONDateTime lVal = obj as ONDateTime;

            if (lVal == null)
            {
                return(1);
            }

            if (Value == null && lVal.Value == null)
            {
                return(0);
            }

            if (Value == null)
            {
                return(-1);
            }

            if (lVal.Value == null)
            {
                return(1);
            }

            return(TypedValue.CompareTo(lVal.TypedValue));
        }
Пример #2
0
        /// <summary>
        /// Creates XML elements from the data of the system.
        /// </summary>
        /// <param name="xmlWriter">Object with the XML message to add new information and return to client side</param>
        /// <param name="val">Value to be puted inside the XML message</param>
        /// <param name="dtdVersion">Version of the DTD that follows the XML message</param>
        /// <param name="xmlElement">Element of the XML that is checked</param>
        public static void ON2XML(XmlWriter xmlWriter, ONDateTime val, double dtdVersion, string xmlElement)
        {
            if (val == null)
            {
                if (xmlElement == ONXml.XMLTAG_V)
                    xmlWriter.WriteElementString(xmlElement, "");
                else
                    xmlWriter.WriteElementString(ONXml.XMLTAG_NULL, null);
            }
            else
            {
                if (dtdVersion < 2.0) // Apply the locale format
                    xmlWriter.WriteElementString(xmlElement, val.TypedValue.ToString());
                else
                {
                    xmlWriter.WriteStartElement(xmlElement);
                    if (xmlElement == ONXml.XMLTAG_OIDFIELD && dtdVersion > 2.0)
                        xmlWriter.WriteAttributeString("Type", "datetime");

                    if (val.TypedValue.Millisecond == 0)
                        xmlWriter.WriteString(val.TypedValue.ToString("yyyy-MM-ddTHH:mm:ss"));
                    else
                        xmlWriter.WriteString(val.TypedValue.ToString("yyyy-MM-ddTHH:mm:ss.fff"));
                    xmlWriter.WriteEndElement();
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="val">Value for this type</param>
 public ONDateTime(ONDateTime val)
 {
     if (val == null)
         Value = null;
     else
         Value = val.Value;
 }
Пример #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="onContext">Context with all the information about the execution of the request</param>
 /// <param name="className">Name of the class that represents the instance</param>
 /// <param name="idClass">Identificator of the class</param>
 public ONInstance(ONContext onContext, string className, string idClass)
 {
     ClassName = className;
     IdClass = idClass;
     Oid = null;
     Lmd = ONDateTime.Null;
     Modified = false;
     OnContext = onContext;
 }
Пример #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="val">Value for this type</param>
 public ONDateTime(ONDateTime val)
 {
     if (val == null)
     {
         Value = null;
     }
     else
     {
         Value = val.Value;
     }
 }
Пример #6
0
        public static ONDateTime Min(ONDateTime obj1, ONDateTime obj2)
        {
            if (((object)obj1 == null) || (obj1.Value == null) || ((object)obj2 == null) || (obj2.Value == null))
            {
                throw new ONNullException(null);
            }

            if (DateTime.Compare(obj1.TypedValue, obj2.TypedValue) >= 0)
            {
                return(obj2);
            }
            else
            {
                return(obj1);
            }
        }
Пример #7
0
        public static ONDateTime Min(ONDateTime obj1, ONDateTime obj2)
        {
            if (((object) obj1 == null) || (obj1.Value == null) ||((object) obj2 == null) || (obj2.Value == null))
                throw new ONNullException(null);

            if (DateTime.Compare(obj1.TypedValue, obj2.TypedValue) >= 0)
                return obj2;
            else
                return obj1;
        }
Пример #8
0
        /// <summary>
        /// This function extracts the information related to the time part of adatetime (hour, minute, second), discarding the date related information (year, month, day)
        /// </summary>				
        public static ONTime getTimePart(ONDateTime adatetime)
        {
            if (adatetime == null)
                return ONTime.Null;

            DateTime lDateTime = adatetime.TypedValue;
            return new ONTime(new DateTime(1970, 1, 1, lDateTime.Hour, lDateTime.Minute, lDateTime.Second));
        }
Пример #9
0
        /// <summary>
        /// This function extracts the information related to the date part of adatetime (year, month, day), discarding the time related information (hour, minute, second)
        /// </summary>			
        public static ONDate getDatePart(ONDateTime adatetime)
        {
            if (adatetime == null )
                return ONDate.Null;

            return new ONDate(adatetime.TypedValue.Date);
        }
Пример #10
0
        /// <summary>
        /// Return the days of difference between datetime1 and datetime2
        /// </summary>		
        public static ONInt daysDifferenceFromDateTime(ONDateTime datetime1, ONDateTime datetime2)
        {
            if (datetime1 == null || datetime2 == null)
                return ONInt.Null;

            if (datetime1 > datetime2)
                return new ONInt(0);

            return new ONInt(datetime2.TypedValue.Subtract(datetime1.TypedValue).Days);
        }
Пример #11
0
        /// <summary>
        /// Converts aDate to a string of the form: dow mon dd hh:mm:ss zzz yyyy
        /// </summary>
        public static ONString dateTimeToString(ONDateTime aDateTime)
        {
            if (aDateTime == null)
                return ONString.Null;

            return new ONString(aDateTime.TypedValue.ToString("MMMM dd, yyyy HH:mm:ss"));
        }
Пример #12
0
        /// <summary>
        /// Compare two datetimes for equality
        /// </summary>				
        /// <returns>true if and only if the argument adatetime1 represents the same datetime as adatetime2</returns>
        public static ONBool datetimeEquals(ONDateTime adatetime1, ONDateTime adatetime2)
        {
            if (adatetime1 == null || adatetime2 == null)
                return ONBool.Null;

            return new ONBool(adatetime1.TypedValue.Equals(adatetime2.TypedValue));
        }
Пример #13
0
        /// <summary>
        /// Tests if adatetime1 is before the specified datetime adatetime2
        /// </summary>
        /// <returns>true if and only if adatetime1 is strictly earlier than the datetime represented by adatetime2</returns>
        public static ONBool datetimeBefore(ONDateTime adatetime1, ONDateTime adatetime2)
        {
            if (adatetime1 == null || adatetime2 == null)
                return ONBool.Null;

            return new ONBool(adatetime1.TypedValue < adatetime2.TypedValue);
        }
Пример #14
0
        /// <summary>
        /// Returns a datetime to which a specified time interval has been added.Interval : The interval of time you want to add.
        /// </summary>				
        public static ONDateTime dateTimeAdd(ONString interval, ONInt number, ONDateTime adatetime )
        {
            if (interval == null || number == null || adatetime == null)
                return ONDateTime.Null;

            switch (interval.TypedValue)
            {
                case "yyyy":
                    return new ONDateTime(adatetime.TypedValue.AddYears(number.TypedValue));
                case "m":
                    return new ONDateTime(adatetime.TypedValue.AddMonths(number.TypedValue));
                case "d":
                    return new ONDateTime(adatetime.TypedValue.AddDays(number.TypedValue));
                case "h":
                    return new ONDateTime(adatetime.TypedValue.AddHours(number.TypedValue));
                case "n":
                    return new ONDateTime(adatetime.TypedValue.AddMinutes(number.TypedValue));
                case "s":
                    return new ONDateTime(adatetime.TypedValue.AddSeconds(number.TypedValue));
                default :
                    return new ONDateTime(adatetime.TypedValue);
            }
        }
Пример #15
0
 /// <summary>
 /// Method of Copy
 /// </summary>
 /// <param name="instance">Instance to be copied</param>
 public virtual void Copy(ONInstance instance)
 {
     if (instance != null)
     {
         OnContext = instance.OnContext;
         ClassName = instance.ClassName;
         if ((object)instance.Lmd.Value == null)
             Lmd = null;
         else if (instance.Lmd.Value == null)
             Lmd = ONDateTime.Null;
         else
             Lmd = new ONDateTime(instance.Lmd.TypedValue);
         Modified = instance.Modified;
     }
 }