예제 #1
0
        public async Task <int[]> CalculateSunTime(bool background)
        {
            int[] sundate = new int[4];
            int[] sun     = new int[2];
            if (!background)
            {
                BasicGeoposition position = await GetUserPosition();

                Properties.Settings.Default.LocationLatitude  = position.Latitude;
                Properties.Settings.Default.LocationLongitude = position.Longitude;
                sun = SunDate.CalculateSunriseSunset(position.Latitude, position.Longitude);
            }
            else if (background)
            {
                sun = SunDate.CalculateSunriseSunset(Properties.Settings.Default.LocationLatitude, Properties.Settings.Default.LocationLongitude);
            }


            //Add offset to sunrise and sunset hours using Settings

            //Remove old offset first if new offset is zero to preserve temporal integrity
            DateTime sunrise = new DateTime(1, 1, 1, sun[0] / 60, sun[0] - (sun[0] / 60) * 60, 0);

            sunrise = sunrise.AddMinutes(Properties.Settings.Default.LightOffset);

            DateTime sunset = new DateTime(1, 1, 1, sun[1] / 60, sun[1] - (sun[1] / 60) * 60, 0);

            sunset = sunset.AddMinutes(Properties.Settings.Default.DarkOffset);

            sundate[0] = sunrise.Hour;   //sunrise hour
            sundate[1] = sunrise.Minute; //sunrise minute
            sundate[2] = sunset.Hour;    //sunset hour
            sundate[3] = sunset.Minute;  //sunset minute
            return(sundate);
        }
예제 #2
0
        public async Task <int[]> CalculateSunTime(bool background)
        {
            int[] sundate = new int[2];
            int[] sun     = new int[2];
            if (!background)
            {
                BasicGeoposition position = await GetUserPosition();

                Properties.Settings.Default.LocationLatitude  = position.Latitude;
                Properties.Settings.Default.LocationLongitude = position.Longitude;
                sun = SunDate.CalculateSunriseSunset(position.Latitude, position.Longitude);
            }
            else if (background)
            {
                sun = SunDate.CalculateSunriseSunset(Properties.Settings.Default.LocationLatitude, Properties.Settings.Default.LocationLongitude);
            }
            sundate[0] = new DateTime(1, 1, 1, 1 + sun[0] / 60, sun[0] - (sun[0] / 60) * 60, 0).Hour; //sunrise
            sundate[1] = new DateTime(1, 1, 1, 1 + sun[1] / 60, sun[1] - (sun[1] / 60) * 60, 0).Hour; //sunset
            return(sundate);
        }