Beispiel #1
0
        public void MinuteRounding()
        {
            DateTime comps1   = TestUtils.MakeDate(2015, 1, 1, 10, 2, 29);
            DateTime rounded1 = CalendarUtil.RoundedMinute(comps1);

            Assert.IsTrue(rounded1.Minute == 2);
            Assert.IsTrue(rounded1.Second == 0);

            DateTime comps2   = TestUtils.MakeDate(2015, 1, 1, 10, 2, 31);
            DateTime rounded2 = CalendarUtil.RoundedMinute(comps2);

            Assert.IsTrue(rounded2.Minute == 3);
            Assert.IsTrue(rounded2.Second == 0);
        }
    public static void Main(string[] args)
    {
        double jd = CalendarUtil.toJulianDate(1987, 4, 10, 0, 0, 0.0);
        double t  = getJulianCentury(jd);
        double ln = getLongitudeNutation(jd);
        double on = getObliquityNutation(jd);

        Console.WriteLine(jd);
        Console.WriteLine(t);
        Console.WriteLine(toDegrees(ln));
        Console.WriteLine(toDegrees(ln) * 3600);
        Console.WriteLine(toDegrees(on));
        Console.WriteLine(toDegrees(on) * 3600);
    }
        /// <summary>
        /// Refresh the content of day grids according to year and month
        /// Author: ChuyangLiu
        /// </summary>
        public void Refresh(int year, int month)
        {
            Reset();
            int firstDayIndex = CalendarUtil.GetWeekOfTheFirstDay(year, month);
            int daysOfMonth   = CalendarUtil.GetDaysOfMonth(year, month);

            for (int i = firstDayIndex, cnt = 0; cnt < daysOfMonth; ++i, ++cnt)
            {
                this[i].Day    = cnt + 1;
                this[i].Enable = true;
                this[i].ReloadItems(year, month);
            }
            Year          = year;
            Month         = month;
            FirstDayIndex = firstDayIndex;
        }
Beispiel #4
0
 public void LeapYear()
 {
     Assert.IsFalse(CalendarUtil.IsLeapYear(2015));
     Assert.IsTrue(CalendarUtil.IsLeapYear(2016));
     Assert.IsTrue(CalendarUtil.IsLeapYear(1600));
     Assert.IsTrue(CalendarUtil.IsLeapYear(2000));
     Assert.IsTrue(CalendarUtil.IsLeapYear(2400));
     Assert.IsFalse(CalendarUtil.IsLeapYear(1700));
     Assert.IsFalse(CalendarUtil.IsLeapYear(1800));
     Assert.IsFalse(CalendarUtil.IsLeapYear(1900));
     Assert.IsFalse(CalendarUtil.IsLeapYear(2100));
     Assert.IsFalse(CalendarUtil.IsLeapYear(2200));
     Assert.IsFalse(CalendarUtil.IsLeapYear(2300));
     Assert.IsFalse(CalendarUtil.IsLeapYear(2500));
     Assert.IsFalse(CalendarUtil.IsLeapYear(2600));
 }
        public CalendarConvertorViewModel()
        {
            DurationHeader = "Calendar"; //Convertor

            #region Initialize

            _ethioDays          = new ObservableCollection <ListDataItem>();
            _ethioMonths        = new ObservableCollection <ListDataItem>();
            _ethioYears         = new ObservableCollection <ListDataItem>();
            _selectedEthioDay   = new ListDataItem();
            _selectedEthioMonth = new ListDataItem();
            _selectedEthioYear  = new ListDataItem();

            #endregion

            #region Load Properties

            for (int i = 1; i <= 30; i++)
            {
                EthioDays.Add(new ListDataItem {
                    Display = i.ToString(), Value = i
                });
            }

            for (int i = 1; i <= 12; i++)
            {
                string monthNo = " (" + i + ")";
                EthioMonths.Add(new ListDataItem {
                    Display = CalendarUtil.GetAmhMonth(i - 1) + monthNo, Value = i
                });
            }
            EthioMonths.Add(new ListDataItem {
                Display = CalendarUtil.GetAmhMonth(12) + " (13)", Value = 13
            });

            for (int i = 1900; i <= 2020; i++)
            {
                EthioYears.Add(new ListDataItem {
                    Display = i.ToString(), Value = i
                });
            }

            #endregion

            Messenger.Default.Register <DateTime>(this, message => { SelectedDate = message; });
        }
        public static void Test24Calendar1()
        {
            SolarTerms solarTerms = new SolarTerms();
            ArrayList  list       = solarTerms.listArr;

            foreach (SolarVo term in list)
            {
                double jd = getJulianDayInYearForTermOrder(term, 2020);
                jd -= CalendarUtil.getDeltaT(jd) / 86400;       // 由TT转换成UTC
                DateTime cal = fromJulianDate(jd + 8.0 / 24.0); // 东8区
                Console.WriteLine(term.Name + ": " +
                                  String.Format("{0}-{1}-{2} {3}:{4}:{5}.{6}", cal.Year,
                                                cal.Month, cal.Day,
                                                cal.Hour, cal.Minute,
                                                cal.Second, cal.Millisecond));
            }
        }
    public static void main(String[] args)
    {
        SolarTerms solarTerms = new SolarTerms();
        ArrayList  list       = solarTerms.listArr;

        foreach (SolarVo term in list)
        {
            double jd = getJulianDayInYearForTermOrder(term, 2020);
            jd -= CalendarUtil.getDeltaT(jd) / 86400;       // 由TT转换成UTC
            DateTime cal = fromJulianDate(jd + 8.0 / 24.0); // 东8区
            Console.WriteLine(term.Name + ": " +
                              String.Format("%04d-%02d-%02d %02d:%02d:%02d.%03d", cal.Year,
                                            cal.Month + 1, cal.Date,
                                            cal.Hour, cal.Minute,
                                            cal.Second, cal.Millisecond));
        }
    }
        public static void TestOtherFunction()
        {
            double jd = CalendarUtil.toJulianDate(1987, 4, 10, 0, 0, 0.0);
            double l  = getSunEclipticLongitudeForEarth(jd);
            double b  = getSunEclipticLatitudeForEarth(jd);
            double r  = getSunRadiusForEarth(jd);
            double dl = vsop2Fk5LongitudeCorrection(l, b, jd);
            double db = vsop2Fk5LatitudeCorrection(l, b, jd);

            Console.WriteLine(jd);
            Console.WriteLine(l);
            Console.WriteLine(b);
            Console.WriteLine(r);
            Console.WriteLine(dl);
            Console.WriteLine(db);

            Console.WriteLine(toDegrees(getEarthEclipticLongitudeForMoon(2448724.5)));
        }
        public static void Test24Calendar()
        {
            for (int month = 1; month <= 12; month++)
            {
                ArrayList jds = getJulianDayInYearAndMonthForNewMoon(2020, month);

                for (int i = 0; i < jds.Count; i++)
                {
                    double jd = (double)jds[i];
                    jd -= CalendarUtil.getDeltaT(jd) / 86400;       // 由TT转换成UTC
                    DateTime cal = fromJulianDate(jd + 8.0 / 24.0); // 东8区
                    // DateTime cal = fromJulianDate(jd);
                    Console.WriteLine(String.Format("{0}-{1}-{2} {3}:{4}:{5}.{6}",
                                                    cal.Year, cal.Month, cal.Day,
                                                    cal.Hour, cal.Minute,
                                                    cal.Second, cal.Millisecond));
                }
            }
        }
Beispiel #10
0
        //private int _monitorTimerDelay = 1800000; //30 minute
        //private Timer _monitorTimer;

        //private string _userName;
        //private string _agencyName;

        #endregion

        #region Constructor

        public MainViewModel()
        {
            EmployeeViewModel.LoadData = true;
            CurrentViewModel           = EmployeeViewModel;

            //    HeaderText = "PinnaFace - (" + Singleton.ProductActivation.LicensedTo + ") " +
            //    Singleton.User.UserName + " - " +
            //    DateTime.Now.ToString("dd/MM/yyyy") + " - " +
            //    CalendarUtil.GetEthCalendarFormated(DateTime.Now, "/") + " - " +
            //    new ProductActivationDTO().BiosSn;

            HeaderTitle = "PinnaFace, Overseas Employment Management System (" +
                          Singleton.User.UserName + ") - " +
                          DateTime.Now.ToString("dd/MM/yyyy") + " (" +
                          CalendarUtil.GetEthCalendarFormated(DateTime.Now, "-") + ") - " +
                          new ProductActivationDTO().BiosSn;

            string header = Singleton.ProductActivation.LicensedTo;

            HeaderText = header.Length > 40
                ? Singleton.ProductActivation.LicensedTo.Substring(0, 38) + "..."
                : Singleton.ProductActivation.LicensedTo; // "PinnaFace - Employees List";

            CheckRoles();

            var worker = new BackgroundWorker();

            worker.DoWork             += DoWork;
            worker.RunWorkerCompleted += worker_RunWorkerCompleted;
            worker.RunWorkerAsync();

            //try
            //{
            //    if(Singleton.BuildType==BuildType.Production)
            //    if (Environment.MachineName.ToLower().Equals("pinnaserver"))
            //        Start();

            //}
            //catch (Exception exception)
            //{
            //    LogUtil.LogError(ErrorSeverity.Critical, "MainViewModel-Environment.MachineName", exception.Message + exception.InnerException, "", "");
            //}
        }
 private void SchichtmodellErstellen_Loaded(object sender, RoutedEventArgs e)
 {
     string[] days = CalendarUtil.GetDayNames();
     string[] rows = new string[days.Length + 2];
     days.CopyTo(rows, 0);
     rows[rows.Length - 2] = "Wochentage";
     rows[rows.Length - 1] = "Werktage";
     foreach (string rowName in rows)
     {
         LabelledStackPanel panel = new LabelledStackPanel();
         panel.LabelText   = rowName + ":";
         panel.LabelWidth  = 100;
         panel.Orientation = Orientation.Horizontal;
         Thickness mar = new Thickness();
         mar.Left     = 10;
         mar.Right    = 10;
         mar.Top      = 10;
         panel.Margin = mar;
         mainStack.Children.Add(panel);
         panel.Children.Add(new TimePicker_VonBis_Appending());
     }
     mainStack.Children[7].Visibility = Visibility.Collapsed;
     mainStack.Children[8].Visibility = Visibility.Collapsed;
 }
Beispiel #12
0
        private void UpdateDisplay(object state)
        {
            int _y  = DateTime.Now.Year;
            int _m  = DateTime.Now.Month;
            int _d  = DateTime.Now.Day;
            int _h  = DateTime.Now.Hour;
            int _mi = DateTime.Now.Minute;

            progress_hour.Dispatcher.Invoke
            (
                new Action
                (
                    delegate
            {
                //更新小时进度条
                int c = CalendarUtil.GetTimeValueByTimeUnit(DateTime.Now, CalendarUtil.TimeValueType.HOUR, CalendarUtil.TimeValueType.SECOND, CalendarUtil.TimeCalculationMode.CURRENT);
                int t = CalendarUtil.GetTimeValueByTimeUnit(DateTime.Now, CalendarUtil.TimeValueType.HOUR, CalendarUtil.TimeValueType.SECOND, CalendarUtil.TimeCalculationMode.TOTAL) - 1;
                progress_hour.Value = (double)c / t * 100;
                lbl_hour.Content    = Math.Round((double)c / t * 100, 2) + "%";
                //Debug.WriteLine("小时:" + c + "/" + t);
            }
                )
            );

            progress_month.Dispatcher.Invoke
            (
                new Action
                (
                    delegate
            {
                //更新月份进度条
                int currentOfMonth   = CalendarUtil.GetTimeValueByTimeUnit(DateTime.Now, CalendarUtil.TimeValueType.MONTH, CalendarUtil.TimeValueType.SECOND, CalendarUtil.TimeCalculationMode.CURRENT);
                int totalOfMonth     = CalendarUtil.GetTimeValueByTimeUnit(DateTime.Now, CalendarUtil.TimeValueType.MONTH, CalendarUtil.TimeValueType.SECOND, CalendarUtil.TimeCalculationMode.TOTAL);
                progress_month.Value = ((double)currentOfMonth / totalOfMonth) * 100;
                lbl_month.Content    = Math.Round((double)currentOfMonth / totalOfMonth * 100, 4) + "%";
                //Debug.WriteLine("月:" + currentOfMonth + "/" + totalOfMonth);
            }
                )
            );

            progress_today.Dispatcher.Invoke(
                new Action
                (
                    delegate
            {
                //更新今天的进度条
                double c             = CalendarUtil.GetCurrentSecondOfDay();
                double t             = 86400.0 - 1;
                double v             = c / t * 100;
                progress_today.Value = Math.Round(v, 1);
                lbl_today.Content    = Math.Round(v, 3) + "%";
            }));

            progress_year.Dispatcher.Invoke(
                new Action
                (
                    delegate
            {
                //今年的进度
                int year_MaxValue     = CalendarUtil.GetTimeValueByTimeUnit(DateTime.Now, CalendarUtil.TimeValueType.YEAR, CalendarUtil.TimeValueType.SECOND, CalendarUtil.TimeCalculationMode.TOTAL) - 1;
                int year_CurrentValue = CalendarUtil.GetTimeValueByTimeUnit(DateTime.Now, CalendarUtil.TimeValueType.YEAR, CalendarUtil.TimeValueType.SECOND, CalendarUtil.TimeCalculationMode.CURRENT);
                progress_year.Value   = ((double)year_CurrentValue) / year_MaxValue * 100;
                lbl_year.Content      = Math.Round((double)year_CurrentValue / year_MaxValue * 100, 5) + "%";
                //Debug.WriteLine("年:" + year_CurrentValue + "/" + year_MaxValue);
            }
                ));

            //分钟进度
            progress_minute.Dispatcher.Invoke(
                new Action
                (
                    delegate
            {
                int m = DateTime.Now.Second;
                //因为从0开始,所以到59
                progress_minute.Value = Math.Ceiling(m / 59.0 * 100);
                lbl_minute.Content    = Math.Round(m / 59.0 * 100, 0) + "%";
            }));
        }
Beispiel #13
0
        private PrayerTimes(Coordinates coordinates, DateTime date, CalculationParameters parameters)
        {
            DateTime?tempFajr    = null;
            DateTime?tempSunrise = null;
            DateTime?tempDhuhr   = null;
            DateTime?tempAsr     = null;
            DateTime?tempMaghrib = null;
            DateTime?tempIsha    = null;

            //DateTime calendar = date.ToUniversalTime();
            int year      = date.Year;
            int dayOfYear = date.DayOfYear;

            SolarTime solarTime = new SolarTime(date, coordinates);

            TimeComponents timeComponents = TimeComponents.FromDouble(solarTime.Transit);
            DateTime?      transit        = timeComponents?.DateComponents(date);

            timeComponents = TimeComponents.FromDouble(solarTime.Sunrise);
            DateTime?sunriseComponents = timeComponents?.DateComponents(date);

            timeComponents = TimeComponents.FromDouble(solarTime.Sunset);
            DateTime?sunsetComponents = timeComponents?.DateComponents(date);

            bool error = transit == null || sunriseComponents == null || sunsetComponents == null;

            if (!error)
            {
                tempDhuhr   = transit;
                tempSunrise = sunriseComponents;
                tempMaghrib = sunsetComponents;

                timeComponents = TimeComponents.FromDouble(
                    solarTime.Afternoon(parameters.Madhab.GetShadowLength()));

                if (timeComponents != null)
                {
                    tempAsr = timeComponents.DateComponents(date);
                }

                // get night length
                DateTime tomorrowSunrise = sunriseComponents.Value.AddDays(1);
                double   night           = tomorrowSunrise.GetTime() - sunsetComponents.Value.GetTime();

                timeComponents = TimeComponents
                                 .FromDouble(solarTime.HourAngle(-parameters.FajrAngle, false));

                if (timeComponents != null)
                {
                    tempFajr = timeComponents.DateComponents(date);
                }

                if (parameters.Method == CalculationMethod.MOON_SIGHTING_COMMITTEE &&
                    coordinates.Latitude >= 55)
                {
                    tempFajr = sunriseComponents.Value.AddSeconds(-1 * (int)(night / 7000));
                }

                NightPortions nightPortions = parameters.NightPortions();

                DateTime safeFajr;
                if (parameters.Method == CalculationMethod.MOON_SIGHTING_COMMITTEE)
                {
                    safeFajr = SeasonAdjustedMorningTwilight(coordinates.Latitude, dayOfYear, year, sunriseComponents.Value);
                }
                else
                {
                    double portion       = nightPortions.Fajr;
                    long   nightFraction = (long)(portion * night / 1000);
                    safeFajr = sunriseComponents.Value.AddSeconds(-1 * (int)nightFraction);
                }

                if (tempFajr == null || tempFajr.Value.Before(safeFajr))
                {
                    tempFajr = safeFajr;
                }

                // Isha calculation with check against safe value
                if (parameters.IshaInterval > 0)
                {
                    tempIsha = tempMaghrib.Value.AddSeconds(parameters.IshaInterval * 60);
                }
                else
                {
                    timeComponents = TimeComponents.FromDouble(
                        solarTime.HourAngle(-parameters.IshaAngle, true));

                    if (timeComponents != null)
                    {
                        tempIsha = timeComponents.DateComponents(date);
                    }

                    if (parameters.Method == CalculationMethod.MOON_SIGHTING_COMMITTEE &&
                        coordinates.Latitude >= 55)
                    {
                        long nightFraction = (long)night / 7000;
                        tempIsha = sunsetComponents.Value.AddSeconds(nightFraction);
                    }

                    DateTime safeIsha;
                    if (parameters.Method == CalculationMethod.MOON_SIGHTING_COMMITTEE)
                    {
                        safeIsha = PrayerTimes.SeasonAdjustedEveningTwilight(
                            coordinates.Latitude, dayOfYear, year, sunsetComponents.Value);
                    }
                    else
                    {
                        double portion       = nightPortions.Isha;
                        long   nightFraction = (long)(portion * night / 1000);
                        safeIsha = sunsetComponents.Value.AddSeconds(nightFraction);
                    }

                    if (tempIsha == null || (tempIsha.Value.After(safeIsha)))
                    {
                        tempIsha = safeIsha;
                    }
                }
            }

            if (error || tempAsr == null)
            {
                // if we don't have all prayer times then initialization failed
                this.Fajr    = DateTime.MinValue;
                this.Sunrise = DateTime.MinValue;
                this.Dhuhr   = DateTime.MinValue;
                this.Asr     = DateTime.MinValue;
                this.Maghrib = DateTime.MinValue;
                this.Isha    = DateTime.MinValue;
            }
            else
            {
                // Assign final times to public struct members with all offsets
                this.Fajr    = CalendarUtil.RoundedMinute(tempFajr.Value.AddMinutes(parameters.Adjustments.Fajr + parameters.MethodAdjustments.Fajr));
                this.Sunrise = CalendarUtil.RoundedMinute(tempSunrise.Value.AddMinutes(parameters.Adjustments.Sunrise + parameters.MethodAdjustments.Sunrise));
                this.Dhuhr   = CalendarUtil.RoundedMinute(tempDhuhr.Value.AddMinutes(parameters.Adjustments.Dhuhr + parameters.MethodAdjustments.Dhuhr));
                this.Asr     = CalendarUtil.RoundedMinute(tempAsr.Value.AddMinutes(parameters.Adjustments.Asr + parameters.MethodAdjustments.Asr));
                this.Maghrib = CalendarUtil.RoundedMinute(tempMaghrib.Value.AddMinutes(parameters.Adjustments.Maghrib + parameters.MethodAdjustments.Maghrib));
                this.Isha    = CalendarUtil.RoundedMinute(tempIsha.Value.AddMinutes(parameters.Adjustments.Isha + parameters.MethodAdjustments.Isha));
            }
        }
Beispiel #14
0
 /// <summary>
 /// Calculate PrayerTimes
 /// </summary>
 /// <param name="coordinates">the coordinates of the location</param>
 /// <param name="date">the date components for that location</param>
 /// <param name="params">he parameters for the calculation</param>
 public PrayerTimes(Coordinates coordinates, DateComponents date, CalculationParameters parameters)
     : this(coordinates, CalendarUtil.ResolveTime(date), parameters)
 {
 }