Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.04 KB | None | 0 0
  1. var allowExceedingTime = viewModel?.assessment?.allowExceedingTime ?? true
  2. var allowLateSubmission = viewModel?.assessment?.allowLateSubmission ?? true
  3. let assessmentTime = viewModel?.assessment?.time ?? 0
  4.  
  5. if assessmentTime == 0 {
  6.     allowExceedingTime = true
  7. }
  8. if assessmentDueDate == nil {
  9.     allowLateSubmission = true
  10. }
  11.  
  12. var timerDate: Date?
  13. if allowExceedingTime && !allowLateSubmission {
  14.     // Timer = Max Due Date
  15.     timerDate = assessmentDueDate
  16. } else if !allowExceedingTime && allowLateSubmission {
  17.     // Timer = Start Time + Duration
  18.     timerDate = Calendar.current.date(byAdding: .minute, value: assessmentTime, to: Date())
  19. } else if !allowExceedingTime && !allowLateSubmission {
  20.     // Timer = min(Due Date, (Start Time + Duration))
  21.     timerDate = min(assessmentDueDate ?? Date(), Calendar.current.date(byAdding: .minute, value: assessmentTime, to: Date()) ?? Date())
  22. } else {
  23.     // No timer needed
  24. }
  25.  
  26. if timerDate != nil {
  27.     timerLabel.setCountDownDate(targetDate: timerDate! as NSDate)
  28.     timerLabel.start()
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement