Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Scheduling Events #671

Open
majidsaleem105 opened this issue Oct 7, 2022 · 3 comments
Open

Auto Scheduling Events #671

majidsaleem105 opened this issue Oct 7, 2022 · 3 comments

Comments

@majidsaleem105
Copy link

Hello @gavirawson-apple,

We're trying to schedule some tasks so that they only appear for a specific time on the app side.
For example, we want people to see a task at 08 o'clock in the morning and remove that task from the app at 09 o'clock. So, it should be displayed before 8 o'clock and after 9 o'clock during that day.

I tried to achieve the goal using the
surveySchedule = OCKScheduleElement(start: thisMorning!, end: expiryDate!, interval: DateComponents(hour: 1) )
Where thisMorning = 2022-10-07 08:00:00, and expiryDate = 2022-10-07 09:00:00

But it didn't work as expected. It appears in the app all the time.

Please advise me on how I can achieve my goal.

Thank You,

  • Majid S.
@gavirawson-apple
Copy link
Collaborator

Hello! The interval that's specified here determines when the task is repeated, so setting an hour interval means an event shows up every hour. I believe the default duration of the event is around 2 hours.

But does the event show up every day? That would be strange since the end date is set to an hour after the start date. The end date is the last time an event will ever show up, not the event end time.

What schedule are you trying to achieve? If it is:

"An event should occur every day, between 8am and 9am"

Then the schedule element would look like:

let calendar = Calendar.current
let startOfDay = calendar.startOfDay(for: Date())
let eightInTheMorning = calendar.date(bySettingHour: 8, minute: 0, second: 0, of: startOfDay)!

let element = OCKScheduleElement(
    start: eightInTheMorning,
    end: nil,
    interval: DateComponents(day: 1),
    duration: .hours(1)
)

let schedule = OCKSchedule(composing: [element])

(Do note that this schedule will be relative to the time zone in which it was scheduled!)

@majidsaleem105
Copy link
Author

Hello @gavirawson-apple,

Yes, we want to display that task/event every day like for 1 month so the end date can be set as the last day of the month. I was trying to push the event from the server side every day that's why I was trying to set the same date for both start/end dates.

Thanks for sharing the code snippet. I'll use it as you suggested. Just asking for confirmation:

  1. If I want to display this event for the next 15 days (every day), I need to replace the end: nil parameter with the date after 15 days. Is that correct?
  2. If I want to display this event just once for 1 hour, I need to replace the end: nil parameter with the startOfDay. Is that correct?

Thank You,

  • Majid S.

@gavirawson-apple
Copy link
Collaborator

If I want to display this event for the next 15 days (every day), I need to replace the end: nil parameter with the date after 15 days. Is that correct?

Exactly! The end date should after the end of the 15th event and before (or on) the start of the 16th event, that will ensure only 15 events show up.

If I want to display this event just once for 1 hour, I need to replace the end: nil parameter with the startOfDay. Is that correct?

Similarly, make sure startOfDay occurs after the end of the first event and before (or on) the start of the second event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants