Пример #1
0
        } // getComparable()

        public int Compare(Object o1, Object o2)
        {
            if (o1 == null && o2 == null)
            {
                return(0);
            }
            if (o1 == null)
            {
                return(-1);
            }
            if (o2 == null)
            {
                return(1);
            }
            try
            {
                CsDate dt1 = toDate(o1);
                CsDate dt2 = toDate(o2);
                return(CsDate.CompareTo(dt1, dt2));
            }
            catch (Exception e)
            {
                logger.error("Could not compare {} and {}", o1, o2);
                throw new CsSystemException(e.Message);
            }
        } // Compare()
Пример #2
0
        } // Compare()

        public static CsDate toDate(object value)
        {
            CsDate result = null;

            if (value == null)
            {
                result = null;
            }
            else if (value is CsDate)
            {
                result = (CsDate)value;
            }
            else if (value is Calendar)
            {
                // https://www.tutorialspoint.com/java/util/calendar_gettime.htm
                result = new CsDate(DateTime.Now);
            }
            else if (value is String)
            {
                result = convertFromString((String)value);
            }
            else if (value is CsNumber)
            {
                result = convertFromNumber((CsNumber)value);
            }

            if (result == null)
            {
                logger.warn("Could not convert '{}' to date, returning null", value);
            }

            return(result);
        }
Пример #3
0
        } // convertFromString()

        private static CsDate convertFromNumber(CsNumber value)
        {
            CsNumber numberValue = (CsNumber)value;
            long     long_value  = numberValue.asLong();

            CsNumber n            = new CsNumber(long_value);
            String   string_value = n.ToString();

            // test if the number is actually a format of the type yyyyMMdd
            if (string_value.Length == 8 && (string_value.StartsWith("1") || string_value.StartsWith("2")))
            {
                try
                {
                    string             format = "yyyyMMdd";
                    DateTimeFormatInfo dtfi   = CsDateUtils.createDateFormat(format);
                    return(new CsDate(string_value, format, dtfi));
                }
                catch (Exception e)
                {
                    // do nothing, proceed to next method of conversion
                }
            }

            // test if the number is actually a format of the type yyMMdd
            if (string_value.Length == 6)
            {
                try
                {
                    string             format = "yyMMdd";
                    DateTimeFormatInfo dtfi   = CsDateUtils.createDateFormat(format);
                    return(new CsDate(string_value, format, dtfi));
                }
            #pragma warning disable 0168
                catch (Exception e)
                {
                    // do nothing, proceed to next method of conversion
                }
            #pragma warning restore 0168
            }

            if (long_value > 5000000)
            {
                // Java: this number is most probably amount of milliseconds since 1970
                // C#:   this number is most probably amount of milliseconds since 1900
                CsDate d = new CsDate(DateTime.Now);
                return(new CsDate(long_value));
            }
            else
            {
                // Java: this number is most probably amount of milliseconds since 1970
                // C#:   this number is most probably amount of milliseconds since 1900
                return(new CsDate(long_value * 1000 * 60 * 60 * 24));
            }
        } // convertFromNumber()
Пример #4
0
        } // _Time_Comparable_Impl_

        public static IComparable <object> getComparable(object o)
        {
            CsDate dt1 = toDate(o);

            return(new _Time_Comparable_Impl_(_instance, dt1));
        } // getComparable()
Пример #5
0
 public _Time_Comparable_Impl_(IComparer <object> instance_arg, CsDate dt1_arg)
 {
     _dt1_      = dt1_arg;
     _instance_ = instance_arg;
 } // constructor