So it reliability would be minutes, era, months, plus

Luckily, Diary will bring all of us with the contrast ( _ : so you can : toGranularity ) means, and this measures up a couple schedules within a given amount of precision.

  • five full minutes following second when Apple Silicone polymer are revealed
  • 3 days after the minute when Fruit Silicon was revealed
assist appleSiliconIntroBig datePlus5Minutes = gregorianCalendar.date( byAdding: .minute, value: 5, to: appleSiliconIntroDate )! let appleSiliconIntroDatePlus3Hours = gregorianCalendar.date( byAdding: .hour, value: 3, to: appleSiliconIntroDate )!

With your Day s defined, you could place evaluate ( _ : so you can : toGranularity ) so you can usepare appleSiliconIntroDate to help you appleSiliconIntroDatePlusstep oneSecond at the next level of granularity.

let test1 = gregorianCalendar.compare( appleSiliconIntroDate, to: appleSiliconIntroDatePlus1Second, toGranularity: .second ) == .orderedSame printing("• appleSiliconIntroDate == appleSiliconIntroDatePlus1Second (with second granularity): \(test1)") let test2 = gregorianCalendar.compare( appleSiliconIntroDate, to: appleSiliconIntroDatePlus1Second, toGranularity: .second ) == .orderedAscending print("• appleSiliconIntroDate < appleSiliconIntroDatePlus1Second>\(test2)")

The newest productivity will tell you you to from the . next number of granularity, appleSiliconIntroDate and you will appleSiliconIntroDatePlus1Second won’t be the same time and you to appleSiliconIntroDatePlus1Second happens once appleSiliconIntroDate .

let test3 = gregorianCalendar.compare( appleSiliconIntroDate, to: appleSiliconIntroDatePlus1Second, toGranularity: .minute ) == .orderedSame print("• appleSiliconIntroDate == appleSiliconIntroDatePlus1Second (with minute granularity): \(test3)")

Within . 2nd amount of granularity, compare ( _ : in order to : toGranularity ) profile one to appleSiliconIntroDate and you may appleSiliconIntroDatePlus1Second is actually around the same time frame. You will see a comparable effect when comparing appleSiliconIntroDate and you can appleSiliconIntroDatePlus5Minutes in the the latest . hours quantity of granularity.

let test4 = gregorianCalendar.compare( appleSiliconIntroDate, to: appleSiliconIntroDatePlus5Minutes, toGranularity: .hour ) == .orderedSame print("• appleSiliconIntroDate == appleSiliconIntroDatePlus5Minutes (with hour granularity): \(test4)")
let test5 = gregorianCalendar.compare( appleSiliconIntroDatePlus5Minutes, to: appleSiliconIntroDate, toGranularity: .minute ) == .orderedDescending print("• appleSiliconIntroDatePlus5Minutes > appleSiliconIntroDate (with minute granularity): \(test5)")

Changing back again to new . second quantity of granularity, evaluate ( _ : to : toGranularity ) tend to claim that appleSiliconIntroDatePlus5Minutes represents a time after appleSiliconIntroDate .

let test6 = gregorianCalendar.compare( appleSiliconIntroDate, to: appleSiliconIntroDatePlus3Hours, toGranularity: .day ) == .orderedSame print("• appleSiliconIntroDate == appleSiliconIntroDatePlus3Hours (with day granularity): \(test6)")

Calculating “2nd Times”

” Towards many other systems, this should wanted enough works, in Quick, a visit in order to Diary ‘s the reason nextDate ( immediately after : matching : matchingPolicy : repeatedTimePolicy : advice : ) method is all that’s necessary.

Programs that plan occurrences usually have to help you determine “2nd times

The idea of “Second times” is easier to demonstrate in place of identify, very I shall do that. Let’s start by some password showing a romantic date symbolizing the latest the very next time it could be step three have always been.

print("\nNext Times:") let next3AmComponents = DateComponents(hour: 3) let next3AmDate = gregorianCalendar.nextDate( after: Date(), matching: next3AmComponents, matchingPolicy: .nextTime )! let next3AmFormatted = dateFormatter.sequence(from: next3AmDate) print("• The next time it will be 3:00 a.m. is: \(next3AmFormatted).")

Do you know the times of your own earlier in the day and next Sundays? nextDate ( ) can do so it calculation in 2 outlines away from password.

let sundayComponents = DateComponents( weekday: 1 ) let previousSunday = gregorianCalendar.nextDate( after: Date(), matching: sundayComponents, matchingPolicy: .nextTime, direction: .backward )! let nextSunday = gregorianCalendar.nextDate( after: Date(), matching: sundayComponents, matchingPolicy: .nextTime, direction: .forward )! dateFormatter.timeStyle = .not one let previousSundayFormatted = dateFormatter.string(from: previousSunday) let nextSundayFormatted = dateFormatter.string(from: nextSunday) print("• Grekland kvinnor för äktenskap The previous Sunday was \(previousSundayFormatted).") print("• The next Sunday will be \(nextSundayFormatted).")

By the form the fresh new elective assistance : parameter to . backward , you can buy new “early in the day second time.” Which is the method that you got the go out towards the earlier in the day Sunday.

Of many meetings are booked inside the relative conditions, for example “the third Tuesday of one’s month.” Whenever is the second 3rd Friday of the week?

let nextThirdFridayComponents = DateComponents( weekday: 6, weekdayOrdinal: 3 ) let nextThirdFridayDate = gregorianCalendar.nextDate( after: Date(), matching: nextThirdFridayComponents, matchingPolicy: .nextTime )! let nextThirdFridayFormatted = dateFormatter.string(from: nextThirdFridayDate) print("• The next third Friday of the month will be \(nextThirdFridayFormatted).")

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *