Пример #1
0
 /// <summary>
 /// Convert a Java Date instance to a .Net DateTime instance.
 /// </summary>
 /// <param name="javaDate">Java Date</param>
 /// <returns>DateTime instance</returns>
 public static DateTime ToDateTime(this java.util.Date javaDate)
 {
     if (javaDate == null)
     {
         throw new ArgumentNullException();
     }
     return(new DateTime(DATE_EPOCH_TICKS + (javaDate.getTime() * 10000)));
 }
Пример #2
0
 public void SetBaseline(java.util.Date bStart, java.util.Date bFinish)
 {
     //StartDateBaseline = new DateTime(year: bStart.getYear(), month: bStart.getMonth(), day: bStart.getDay());
     //FinishDateBaseline = new DateTime(year: bFinish.getYear(), month: bFinish.getMonth(), day: bFinish.getDay());
     StartDateBaseline  = new DateTime(1970, 1, 1, 4, 0, 0, DateTimeKind.Utc);
     FinishDateBaseline = new DateTime(1970, 1, 1, 4, 0, 0, DateTimeKind.Utc);
     StartDateBaseline  = StartDateBaseline.AddMilliseconds(bStart.getTime());
     FinishDateBaseline = FinishDateBaseline.AddMilliseconds(bFinish.getTime());
 }
Пример #3
0
        internal static long JavaDateToClrTicks(java.util.Date d)
        {
            long millis = JavaMillisToClrMillis(d.getTime());

            if (DEFAULT_TIME_ZONE.inDaylightTime(d))
            {
                millis += DEFAULT_TIME_ZONE.getDSTSavings();
            }
            return(millis * TimeSpan.TicksPerMillisecond);
        }
Пример #4
0
 public ProjectDates(java.util.Date start, java.util.Date finish)
 {
     if (start != null && finish != null)
     {
         //StartDate = new DateTime(year: start.getYear(), month: start.getMonth(), day: start.getDay());
         //FinishDate = new DateTime(year: finish.getYear(), month: finish.getMonth(), day: finish.getDay());
         StartDate  = new DateTime(1970, 1, 1, 4, 0, 0, DateTimeKind.Utc);
         FinishDate = new DateTime(1970, 1, 1, 4, 0, 0, DateTimeKind.Utc);
         StartDate  = StartDate.AddMilliseconds(start.getTime());
         FinishDate = FinishDate.AddMilliseconds(finish.getTime());
     }
 }
Пример #5
0
        /// <summary>
        /// Converts a Java Date value to a DateTime value
        /// </summary>
        /// <param name="javaDate">The Java date</param>
        /// <returns></returns>
        private static DateTime FromJavaDate(java.util.Date javaDate)
        {
            if (_configTimeZone == null)
            {
                // Read time zone from market-hours-config
                _configTimeZone = MarketHoursDatabase.FromDataFolder().GetDataTimeZone("fxcm", "*", SecurityType.Forex);
            }

            // Convert javaDate to UTC Instant (Epoch)
            var instant = Instant.FromSecondsSinceUnixEpoch(javaDate.getTime() / 1000);

            // Convert to configured TZ then to a .Net DateTime
            return(instant.InZone(_configTimeZone).ToDateTimeUnspecified());
        }
Пример #6
0
        /// <summary>
        /// Convert a DateTime instance to a Java Date instance.
        /// </summary>
        /// <param name="d">DateTime instance</param>
        /// <returns>Java Date instance</returns>
        public static java.util.Date ToJavaDate(this DateTime d)
        {
            TimeSpan ts        = d - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime();
            long     timestamp = (long)ts.TotalMilliseconds;

            java.util.TimeZone tz     = java.util.TimeZone.getDefault();
            java.util.Date     result = new java.util.Date(timestamp - tz.getRawOffset());

            if (tz.inDaylightTime(result) == true)
            {
                int savings = tz.getDSTSavings();
                result = new java.util.Date(result.getTime() - savings);
            }
            return(result);
        }
Пример #7
0
        /// <summary>
        /// Convert a Java Date instance to a nullable .Net DateTime instance.
        /// </summary>
        /// <param name="javaDate">Java Date</param>
        /// <returns>DateTime instance</returns>
        public static DateTime?ToNullableDateTime(this java.util.Date javaDate)
        {
            DateTime?result;

            if (javaDate == null)
            {
                result = null;
            }
            else
            {
                long javaTime  = javaDate.getTime();
                int  dstOffset = java.util.TimeZone.getDefault().getOffset(javaTime);
                result = javaDate == null ? (DateTime?)null : new DateTime(DATE_EPOCH_TICKS + ((javaTime + dstOffset) * 10000));
            }
            return(result);
        }
Пример #8
0
 public void SetCreatedDate(java.util.Date date)
 {
     CreationDate = new DateTime(1970, 1, 1, 4, 0, 0, DateTimeKind.Utc);
     CreationDate = CreationDate.AddMilliseconds(date.getTime());
 }
Пример #9
0
 /// <summary>
 /// Convert a Java Date instance to a nullable .Net DateTime instance.
 /// </summary>
 /// <param name="javaDate">Java Date</param>
 /// <returns>DateTime instance</returns>
 public static DateTime?ToNullableDateTime(this java.util.Date javaDate)
 {
     return(javaDate == null ? (DateTime?)null : new DateTime(DATE_EPOCH_TICKS + (javaDate.getTime() * 10000)));
 }