} // _Number_Comparable_Impl_ //public static IComparable<object> getComparable(object o) //{ // NNumber n = toNumber(o); // return new _Number_Comparable_Impl_(_instance, n); //} // getComparable() public int Compare(object o1, object o2) { NNumber n1 = toNumber(o1); NNumber n2 = toNumber(o2); if (n1 == null && n2 == null) { return(0); } if (n1 == null) { return(-1); } if (n2 == null) { return(1); } if (n1 is NNumber && n2 is NNumber) { return((n1.asBigInteger()).CompareTo(n2.asBigInteger())); } //if (n1 is BigDecimal && n2 is BigDecimal) { // return ((BigDecimal)n1).compareTo((BigDecimal)n2); //} if (NumberComparator.IsIntegerType(n1) && NumberComparator.IsIntegerType(n2)) { return(NInteger.ValueOf(n1).CompareTo(n2.asLong())); } return(NNumber.ValueOf(n1).CompareTo(n2.asLong())); } // Compare()
} // convertFromString() private static NDate convertFromNumber(NNumber value) { NNumber numberValue = (NNumber)value; long long_value = numberValue.asLong(); NNumber n = new NNumber(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 = NDateUtils.createDateFormat(format); return(new NDate(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 = NDateUtils.createDateFormat(format); return(new NDate(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 NDate d = new NDate(DateTime.Now); return(new NDate(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 NDate(long_value * 1000 * 60 * 60 * 24)); } } // convertFromNumber()