Skip to content

Commit

Permalink
[iOS/#369] Timezone 동기화 및 Timer bug fix (#371)
Browse files Browse the repository at this point in the history
* fix: 24시간제 대응

* fix: Polling 할 때마다 Timer 중복 실행되던 이슈 해결

* feat: GMT로 변경하여 시간대 동기화
  • Loading branch information
nemanjabenkovic authored Dec 7, 2023
1 parent 6e8cde2 commit 5f1ea47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ import Foundation
extension Date {
enum FMDateFormmat: String {
case yyyyMMdd = "yyyy-MM-dd"
case yyyyMMddhhmmss = "yyyy-MM-dd hh:mm:ss"
case yyyyMMddhhmmss = "yyyy-MM-dd HH:mm:ssZZZZZ"
}

/// 파라미터로 전달받은 format의 타입으로 Date을 문자열로 변환하여 리턴합니다.
func dateToString(format: FMDateFormmat) -> String {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "ko_KR")
formatter.timeZone = TimeZone(identifier: "Asia/Seoul")
formatter.dateFormat = format.rawValue
return formatter.string(from: self)
}
Expand All @@ -27,10 +25,6 @@ extension DateFormatter {
static func FMDateFormat(dateFormat: Date.FMDateFormmat) -> DateFormatter {
let formatter = DateFormatter()
formatter.dateFormat = dateFormat.rawValue
/// locale & timezone
formatter.locale = Locale(identifier: "ko_KR")
formatter.timeZone = TimeZone(identifier: "Asia/Seoul")
print(Locale.current.identifier, TimeZone.current.identifier)
return formatter
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final class FriendStatusPollingManager: FriendStatusPollingManageable {
guard let friend = friendsStatus.filter({ $0.id == id }).first else { return }
guard let startedTime = friend.startedTime else { continue }
guard let date = startedTime.stringToDate(.yyyyMMddhhmmss) else { continue }
let currentLearningTime = Int(Date().timeIntervalSince(date))
let currentLearningTime = Int(Date().timeIntervalSince(date)) - 1
updateFriendArray.append(UpdateFriend(id: friend.id, currentLearningTime: currentLearningTime))
}
startTimer()
Expand All @@ -72,7 +72,7 @@ final class FriendStatusPollingManager: FriendStatusPollingManageable {
guard let friend = friendsStatus.filter({ $0.id == id }).first else { return }
guard let startedTime = friend.startedTime else { continue }
guard let date = startedTime.stringToDate(.yyyyMMddhhmmss) else { continue }
let currentLearningTime = Int(Date().timeIntervalSince(date))
let currentLearningTime = Int(Date().timeIntervalSince(date)) - 1
updateFriendArray.append(UpdateFriend(id: friend.id, currentLearningTime: currentLearningTime))
}
}
Expand Down Expand Up @@ -153,10 +153,13 @@ final class FriendStatusPollingManager: FriendStatusPollingManageable {

private func startTimer() {
if updateFriendArray.isEmpty { return }
if timerState == .resumed { return }
timerManager.start(completion: increaseLearningTime)
timerState = .resumed
}

private func stopTimer() {
timerManager.cancel()
timerState = .cancled
}
}

0 comments on commit 5f1ea47

Please sign in to comment.