Skip to content

Commit

Permalink
[Refactor] Date+Extension 으로 로직 이동 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
minsangKang committed Aug 25, 2022
1 parent 7b7c338 commit c75e805
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Project_Timer/Global/Extension/Date+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,8 @@ extension Date {
let timeComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: from, to: to)
return (timeComponents.hour ?? 0)*3600 + (timeComponents.minute ?? 0)*60 + (timeComponents.second ?? 0)
}

var truncateSeconds: Date? {
return Calendar.current.date(from: Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: self))
}
}
5 changes: 2 additions & 3 deletions Project_Timer/Logs/ModifyRecordVC/Popup/EditDateVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class EditDateVC: UIViewController {

@IBAction func dateValueChanged(_ sender: UIDatePicker) {
// Presenting ViewController로부터 전달받은 핸들러 실행
guard let changeHandler = dateChangeHandler,
let date = Calendar.current.date(from: Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: sender.date)) else { return }
changeHandler(date)
guard let date = sender.date.truncateSeconds else { return }
self.dateChangeHandler?(date)
}

func configure(date: Date, dateChangeHandler: @escaping DateChangeHandler) {
Expand Down

0 comments on commit c75e805

Please sign in to comment.