Skip to content

Commit

Permalink
[GWL-396] 시간대 15시간 차이나는 버그 수정 (#397)
Browse files Browse the repository at this point in the history
* fix: Date가 15시간 차이나는 버그 수정

* chore: km를 m로 수정

* chore: Timezone설정해서 올바른 시간대로 들어오도록 설정
  • Loading branch information
WhiteHyun authored Dec 12, 2023
1 parent fdf39de commit 7fdb8fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,48 +45,16 @@ extension Record {
}

private static func timeToTime(createdAt: Date, workoutTime: Int) -> (startTime: String, endTime: String)? {
let dateComponents = Calendar.current.dateComponents([.hour, .minute, .second], from: createdAt)
let endDate = createdAt
let startDate = endDate - Double(workoutTime)
let formatter = DateFormatter()
formatter.dateFormat = "HH:mm:ss"
formatter.timeZone = .init(abbreviation: "UTC")

guard
let hour = dateComponents.hour,
let minute = dateComponents.minute,
let second = dateComponents.second
else {
return nil
}

let startSeconds = Time(hour: hour, minute: minute, second: second).toSeconds()
let endSeconds = startSeconds + workoutTime
let start = prettyStyle(time: timeToHourMinuteSecond(seconds: startSeconds))
let end = prettyStyle(time: timeToHourMinuteSecond(seconds: endSeconds))
return (start, end)
}

private static func timeToHourMinuteSecond(seconds: Int) -> Time {
var seconds = seconds
let hour = seconds / 3600
seconds %= 3600
let minute = seconds / 60
seconds %= 60
return Time(hour: hour, minute: minute, second: seconds)
}

private static func prettyStyle(time: Time) -> String {
let formattedHour = String(format: "%02d", time.hour)
let formattedMinute = String(format: "%02d", time.minute)
let formattedSecond = String(format: "%02d", time.second)
return "\(formattedHour):\(formattedMinute):\(formattedSecond)"
}
}

// MARK: - Time

private struct Time {
let hour: Int
let minute: Int
let second: Int
// 날짜를 문자열로 변환
let startDateString = formatter.string(from: startDate)
let endDateString = formatter.string(from: endDate)

func toSeconds() -> Int {
return hour * 3600 + minute * 60 + second
return (startDateString, endDateString)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private extension RecordListViewController {
sport: $0.mode.description,
startTime: $0.startTime,
endTime: $0.endTime,
distance: "\($0.distance)km"
distance: "\($0.distance)m"
)
}
configureSnapShot(items: workoutInformationItems)
Expand Down

0 comments on commit 7fdb8fc

Please sign in to comment.