ToDateTime() public method

public ToDateTime ( int year, int month, int day, int hour, int minute, int second, int millisecond ) : DateTime
year int
month int
day int
hour int
minute int
second int
millisecond int
return DateTime
        public static DateTime DecadeOfDate(DateTime date)
        {
            int      year    = cal.GetYear(date);
            int      decade  = year - (year % 10);
            DateTime newDate = cal.ToDateTime(decade, 1, 1, 0, 0, 0, 0);

            return(newDate);
        }
Example #2
0
        private void SetYearButtons(DateTime decade, DateTime decadeEnd)
        {
            int decadeYear    = _calendar.GetYear(decade);
            int decadeEndYear = _calendar.GetYear(decadeEnd);
            int year;
            int count = -1;

            foreach (object child in _yearView.Children)
            {
                CalendarButton childButton = child as CalendarButton;
                Debug.Assert(childButton != null);
                year = decadeYear + count;

                if (year <= _calendar.MaxSupportedDateTime.Year && year >= _calendar.MinSupportedDateTime.Year)
                {
                    // There should be no time component. Time is 12:00 AM
                    DateTime day = _calendar.ToDateTime(year, 1, 1, 0, 0, 0, 0);
                    childButton.DataContext = day;
                    childButton.SetContentInternal(DateTimeHelper.ToYearString(day, DateTimeHelper.GetCulture(this)));
                    childButton.Visibility = Visibility.Visible;

                    if (Owner != null)
                    {
                        childButton.HasSelectedDays = (_calendar.GetYear(Owner.DisplayDate) == year);

                        if (year < Owner.DisplayDateStartInternal.Year || year > Owner.DisplayDateEndInternal.Year)
                        {
                            childButton.IsEnabled = false;
                            childButton.Opacity   = 0;
                        }
                        else
                        {
                            childButton.IsEnabled = true;
                            childButton.Opacity   = 1;
                        }
                    }

                    // SET IF THE YEAR IS INACTIVE OR NOT: set if the year is a trailing year or not
                    childButton.IsInactive = year <decadeYear || year> decadeEndYear;
                }
                else
                {
                    childButton.DataContext = null;
                    childButton.IsEnabled   = false;
                    childButton.Opacity     = 0;
                }

                count++;
            }
        }
Example #3
0
        public virtual DateTime GetToDate(DateTime dt, System.Globalization.Calendar calendar)
        {
            if (this.Order == 1 && this.FromMonth > this.ToMonth)
            {
                if (calendar.GetMonth(dt) == 12)
                {
                    //در اولین بازه محدوده، ماه شروع در سال قبل قرار گرفته
                    dt = calendar.AddYears(dt, 1);
                }
            }
            if (this.Order == 12 && this.FromMonth > this.ToMonth)
            {
                if (calendar.GetMonth(dt) == 12)
                {
                    //در آخرین بازه محدوده، ماه پایان در سال بعد قرار گرفته
                    dt = calendar.AddYears(dt, 1);
                }
            }
            else if (this.Order == 0 && this.FromMonth >= this.ToMonth)
            {
                //بازه سالانه است و پایان در سال بعد قرار گرفته
                dt = calendar.AddYears(dt, 1);
            }

            if (calendar is PersianCalendar)
            {
                if (calendar.IsLeapYear(calendar.GetYear(dt)) && this.ToMonth == 12 && this.ToDay == 29)
                {
                    return(calendar.ToDateTime(calendar.GetYear(dt), this.ToMonth, 30, 0, 0, 0, 0));
                }
                else
                {
                    return(calendar.ToDateTime(calendar.GetYear(dt), this.ToMonth, this.ToDay, 0, 0, 0, 0));
                }
            }
            else
            {
                if (calendar.IsLeapYear(dt.Year) && this.ToMonth == 2 && this.ToDay == 28)
                {
                    //اگر سال کبسه بود و برای ماه فوریه روز 28 انتخاب شده بود
                    //به صورت خودکار با روز 29 جایگزین می شود
                    return(calendar.ToDateTime(dt.Year, this.ToMonth, 29, 0, 0, 0, 0));
                }
                else
                {
                    return(calendar.ToDateTime(dt.Year, this.ToMonth, this.ToDay, 0, 0, 0, 0));
                }
            }
        }
        /// <summary>
        /// Checks that each day from the given start year to the end year (inclusive) is equal
        /// between the BCL and the Noda Time calendar. Additionally, the number of days in each month and year
        /// and the number of months (and leap year status) in each year is checked.
        /// </summary>
        internal static void AssertEquivalent(Calendar bcl, CalendarSystem noda, int fromYear, int toYear)
        {
            // We avoid asking the BCL to create a DateTime on each iteration, simply
            // because the BCL implementation is so slow. Instead, we just check at the start of each month that
            // we're at the date we expect.
            DateTime bclDate = bcl.ToDateTime(fromYear, 1, 1, 0, 0, 0, 0);
            for (int year = fromYear; year <= toYear; year++)
            {
                Assert.AreEqual(bcl.GetDaysInYear(year), noda.GetDaysInYear(year), "Year: {0}", year);
                Assert.AreEqual(bcl.GetMonthsInYear(year), noda.GetMonthsInYear(year), "Year: {0}", year);
                for (int month = 1; month <= noda.GetMonthsInYear(year); month++)
                {
                    // Sanity check at the start of each month. Even this is surprisingly slow.
                    // (These three tests make up about 20% of the total execution time for the test.)
                    Assert.AreEqual(year, bcl.GetYear(bclDate));
                    Assert.AreEqual(month, bcl.GetMonth(bclDate));
                    Assert.AreEqual(1, bcl.GetDayOfMonth(bclDate));

                    Assert.AreEqual(bcl.GetDaysInMonth(year, month), noda.GetDaysInMonth(year, month),
                        "Year: {0}; Month: {1}", year, month);
                    Assert.AreEqual(bcl.IsLeapYear(year), noda.IsLeapYear(year), "Year: {0}", year);
                    for (int day = 1; day <= noda.GetDaysInMonth(year, month); day++)
                    {
                        LocalDate nodaDate = new LocalDate(year, month, day, noda);
                        Assert.AreEqual(bclDate, nodaDate.ToDateTimeUnspecified(),
                            "Original calendar system date: {0:yyyy-MM-dd}", nodaDate);
                        Assert.AreEqual(nodaDate, LocalDate.FromDateTime(bclDate, noda));
                        Assert.AreEqual(year, nodaDate.Year);
                        Assert.AreEqual(month, nodaDate.Month);
                        Assert.AreEqual(day, nodaDate.Day);
                        bclDate = bclDate.AddDays(1);
                    }
                }
            }
        }
Example #5
0
        private DateTime?ConvertePersianDateToDateTime()
        {
            var persianDate = datePickerPersian.Value;

            int year  = 0;
            int month = 0;
            int day   = 0;

            DateTime?datetime = null;

            if (!string.IsNullOrWhiteSpace(persianDate?.ToString()))
            {
                var splitedPersianDate = persianDate.ToString().Split('/');

                year  = int.Parse(splitedPersianDate[0]);
                month = int.Parse(splitedPersianDate[1]);
                day   = int.Parse(splitedPersianDate[2]);
            }

            if (year != 0 && month != 0 && day != 0)
            {
                datetime = PersianCalendar.ToDateTime(year, month, day, 0, 0, 0, 0);
            }

            return(datetime);
        }
 private void ExecutePosTest(Calendar myCalendar, int year, int month, int day, int hour, int minute,
     int second, int millisecond, int era)
 {
     DateTime actualTime, expectedTime;
     expectedTime = new DateTime(year, month, day, hour, minute, second, millisecond);
     actualTime = myCalendar.ToDateTime(year, month, day, hour, minute, second, millisecond, era);
     Assert.Equal(expectedTime, actualTime);
 }
Example #7
0
 public virtual DateTime GetFromDate(DateTime dt, System.Globalization.Calendar calendar)
 {
     if (this.Order == 1 && this.FromMonth > this.ToMonth)
     {
         if (calendar.GetMonth(dt) == 1)
         {
             //در اولین بازه محدوده، ماه شروع در سال قبل قرار گرفته
             dt = calendar.AddYears(dt, -1);
         }
     }
     else if (this.Order == 0 && this.FromMonth >= this.ToMonth)
     {
         //بازه سالانه است و شروع در سال قبل قرار گرفته
         dt = calendar.AddYears(dt, -1);
     }
     return(calendar.ToDateTime(calendar.GetYear(dt), this.FromMonth, this.FromDay, 0, 0, 0, 0));
 }
        public static bool IsRepresentable( this DateTime date, Calendar calendar, int year, int month, int day )
        {
            Arg.NotNull( calendar, nameof( calendar ) );

            if ( date < calendar.MinSupportedDateTime || date > calendar.MaxSupportedDateTime )
                return false;

            try
            {
                calendar.ToDateTime( year, month, day, date.Hour, date.Minute, date.Second, date.Millisecond );
            }
            catch ( ArgumentOutOfRangeException )
            {
                return false;
            }

            return true;
        }
 private void ExecutePosTest(string errorNum1, string errorNum2, Calendar myCalendar, int year,
     int month, int day, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
 {
     DateTime time;
     int actualDayOfYear, expectedDayOfYear;
     int weekOfYear;
     time = myCalendar.ToDateTime(year, month, day, 0, 0, 0, 0);
     expectedDayOfYear = myCalendar.GetDayOfYear(time);
     weekOfYear = myCalendar.GetWeekOfYear(time, rule, firstDayOfWeek);
     actualDayOfYear = this.GetDayOfYear(time, rule, firstDayOfWeek, weekOfYear, myCalendar);
     Assert.Equal(expectedDayOfYear, actualDayOfYear);
 }
 private void ExecuteAOORETest(Calendar myCalendar, int year, int month, int day, int hour, int minute,
     int second, int millisecond, int era)
 {
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         myCalendar.ToDateTime(year, month, day, hour, minute, second, millisecond, era);
     });
 }
	public DateTime ToDateTime(Calendar cal) {
		return cal.ToDateTime(Year,Month,Day,0,0,0,0,Era);
	}
Example #12
0
	public DateTime(int year, int month, int day,
					int hour, int minute, int second, int millisecond,
				    Calendar calendar)
			{
				if(calendar == null)
				{
					throw new ArgumentNullException("calendar");
				}
				value_ = calendar.ToDateTime(year, month, day, hour,
											  minute, second, millisecond,
											  Calendar.CurrentEra)
								.Ticks;
			}
Example #13
0
 // Constructs a DateTime from a given year, month, day, hour,
 // minute, and second for the specified calendar.
 //
 /// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.DateTime6"]/*' />
 public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar) {
     if (calendar == null)
         throw new ArgumentNullException("calendar");
     ticks = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks;
     if (millisecond < 0 || millisecond >= MillisPerSecond) {
         throw new ArgumentOutOfRangeException("millisecond", String.Format(Environment.GetResourceString("ArgumentOutOfRange_Range"), 0, MillisPerSecond - 1));
     }            
     ticks += millisecond * TicksPerMillisecond;
     if (ticks < MinTicks || ticks > MaxTicks)
         throw new ArgumentException(Environment.GetResourceString("Arg_DateTimeRange"));
 }
Example #14
0
 // Constructs a DateTime from a given year, month, day, hour,
 // minute, and second for the specified calendar.
 //
 /// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.DateTime4"]/*' />
 public DateTime(int year, int month, int day, int hour, int minute, int second, Calendar calendar) {
     if (calendar == null)
         throw new ArgumentNullException("calendar");
     ticks = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks;
 }
Example #15
0
        public static DateTime StartOfMonth( this DateTime date, Calendar calendar )
        {
            Arg.NotNull( calendar, nameof( calendar ) );
            Contract.Ensures( calendar.GetYear( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetYear( date ) ) );
            Contract.Ensures( calendar.GetMonth( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetMonth( date ) ) );

            var year = calendar.GetYear( date );
            var month = calendar.GetMonth( date );
            return calendar.ToDateTime( year, month, 1, date.Hour, date.Minute, date.Second, date.Millisecond );
        }
Example #16
0
 private DateTime GetStartDate(Calendar calendar)
   {
   Int32 year = calendar.TwoDigitYearMax-90;		
   DateTime date = calendar.ToDateTime(year, 1, 1, 1, 1, 1, 980);
   return date;
   }