コード例 #1
0
ファイル: LocalDate.cs プロジェクト: wayneYaw/sonarlint-vs
        /// <summary>
        /// Converts a <see cref="DateTime" /> of any kind to a LocalDate in the specified calendar, ignoring the time of day.
        /// This does not perform any time zone conversions, so a DateTime with a <see cref="DateTime.Kind"/> of
        /// <see cref="DateTimeKind.Utc"/> will still represent the same year/month/day - it won't be converted into the local system time.
        /// </summary>
        /// <param name="dateTime">Value to convert into a Noda Time local date</param>
        /// <param name="calendar">The calendar system to convert into</param>
        /// <returns>A new <see cref="LocalDate"/> with the same values as the specified <c>DateTime</c>.</returns>
        public static LocalDate FromDateTime(DateTime dateTime, [NotNull] CalendarSystem calendar)
        {
            long ticks = dateTime.Ticks - NodaConstants.BclTicksAtUnixEpoch;
            int  days  = TickArithmetic.TicksToDays(ticks);

            return(new LocalDate(days, calendar));
        }
コード例 #2
0
ファイル: LocalDate.cs プロジェクト: wayneYaw/sonarlint-vs
        /// <summary>
        /// Converts a <see cref="DateTime" /> of any kind to a LocalDate in the ISO calendar, ignoring the time of day.
        /// This does not perform any time zone conversions, so a DateTime with a <see cref="DateTime.Kind"/> of
        /// <see cref="DateTimeKind.Utc"/> will still represent the same year/month/day - it won't be converted into the local system time.
        /// </summary>
        /// <param name="dateTime">Value to convert into a Noda Time local date</param>
        /// <returns>A new <see cref="LocalDate"/> with the same values as the specified <c>DateTime</c>.</returns>
        public static LocalDate FromDateTime(DateTime dateTime)
        {
            long ticks = dateTime.Ticks - NodaConstants.BclTicksAtUnixEpoch;
            int  days  = TickArithmetic.TicksToDays(ticks);

            return(new LocalDate(days));
        }