-
Notifications
You must be signed in to change notification settings - Fork 16
[Refactor] #520 - DateFormatter() 인스턴스 메모리 최적화 #528
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
Changes from 7 commits
eb84af0
293ccab
60dc35a
eccbd90
6911398
106ef65
e52cbce
0cb2153
ffae793
6e4a67c
461370b
35e0a09
502d79d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// DateFormatType.swift | ||
// Core | ||
// | ||
// Created by 강윤서 on 3/27/25. | ||
// Copyright © 2025 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum DateFormatType: String { | ||
case iso = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" | ||
case isoWithoutMillis = "yyyy-MM-dd'T'HH:mm:ss" | ||
case dateTimeDash = "yyyy-MM-dd HH:mm:ss" | ||
case dateWithDot = "yyyy.MM.dd" | ||
case dateWithDash = "yyyy-MM-dd" | ||
case dateWithSlash = "yy/MM/dd" | ||
case monthDayWeek = "M월 d일 EEEE" | ||
case monthDayWeekTime = "M월 d일 EEEE H:mm" | ||
case monthDayWeekFullTime = "M월 d일 EEEE HH:mm" | ||
case monthDayWithDot = "MM.dd" | ||
case monthDayWIthDash = "MM-dd" | ||
case time = "HH:mm" | ||
case networkLogger = "dd/MM/yyyy HH:mm:ss" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// DateFormatterManager.swift | ||
// Core | ||
// | ||
// Created by 강윤서 on 3/27/25. | ||
// Copyright © 2025 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public final class DateFormatManager { | ||
public static let shared = DateFormatManager() | ||
|
||
public init() { | ||
formatter.locale = Locale(identifier: "ko_KR") | ||
formatter.timeZone = TimeZone(identifier: "Asia/Seoul") | ||
} | ||
|
||
private var formatter = DateFormatter() | ||
} | ||
|
||
public extension DateFormatManager { | ||
func setFormat(_ format: DateFormatType) { | ||
formatter.dateFormat = format.rawValue | ||
} | ||
|
||
/// 문자열을 원하는 포맷의 Date타입으로 변환 | ||
func stringToDate(_ value: String) -> Date? { | ||
return formatter.date(from: value) | ||
} | ||
|
||
/// date타입을 원하는 포맷의 문자열로 변환 | ||
func dateToString(_ date: Date) -> String { | ||
return formatter.string(from: date) | ||
} | ||
|
||
/// 문자열 날짜를 원하는 포맷의 String타입으로 변환 | ||
/// 변경할 값이 비어있다면 오늘 날짜를 반환 | ||
func transformDateFormat(_ target: String? = nil, from before: DateFormatType? = nil, to after: DateFormatType) -> String { | ||
guard let target, let before | ||
else { | ||
setFormat(after) | ||
return dateToString(Date()) | ||
} | ||
|
||
setFormat(before) | ||
guard let date = stringToDate(target) else { return "00:00" } | ||
|
||
setFormat(after) | ||
return formatter.string(from: date) | ||
} | ||
|
||
/// 서버에서 내려주는 iSO 포맷 타입을 원하는 타입으로 변환 | ||
func serverTimeToString(_ target: String, from format: DateFormatType, to serverFormat: DateFormatType = .iso) -> String { | ||
setFormat(serverFormat) | ||
guard let date = stringToDate(target) else { return "" } | ||
|
||
setFormat(format) | ||
return dateToString(date) | ||
} | ||
|
||
/// 시작 날짜와 종료 날짜 입력 받아 원하는 포맷으로 변경 후 문자열로 반환 | ||
func formatTimeInterval(start: String, end: String) -> String { | ||
setFormat(.monthDayWeekFullTime) | ||
|
||
guard let startDate = stringToDate(start), | ||
let endDate = stringToDate(end) | ||
else { return "" } | ||
|
||
let startString = dateToString(startDate) | ||
|
||
setFormat(.time) | ||
let endString = dateToString(endDate) | ||
|
||
return "\(startString) ~ \(endString)" | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,8 +128,7 @@ extension CalendarCardCVC { | |
extension CalendarCardCVC { | ||
func configureCell(model: HomePresentationModel.RecentSchedule, | ||
userType: UserType) { | ||
// TODO: 서버 - 날짜 포맷 변경 후 반영 | ||
self.dateLabel.text = setDateFormat(date: model.date, to: "MM.dd") | ||
self.dateLabel.text = DateFormatManager.shared.transformDateFormat(model.date, from: .monthDayWIthDash, to: .monthDayWithDot) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 서버에서 받아온 날짜 관련 String을 서버와 약속한 Date format으로 Date를 변환하는 역할은 누구에게 책임이 있다고 생각하시나요? Date값이 Data계층에서 Domain계층으로 넘어갈 때 String 값을 Date값으로 변경하고, Domain에는 가장 순수한 Date 타입만 존재하면 좋을 것 같아요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다시 생각해보니 해당 PR은 메모리 성능 최적화가 중점적이라, PR에서 작업하지 않은 내용을 리뷰한 것 같네요 ㅎㅎ; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 리뷰 감사합니다 !! 기존 코드 수정에만 집중하다 보니 각 레이어의 역할 분리에 대해 깊이 있게 고민하지 못했던 것 같아요. 석우님 말씀처럼 서버에서 받아온 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 피드백 수용해주셔서 감사함다 :) 현 구조에선 toDomain()에서 String을 Date로 변환하는 것이 가장 편할 것 같네요. 이외에도 서버의 requestBody의 json을 Decodable 구조체로 디코딩할 때 JSONDecoder의 dateStrategyFormat값을 통해 처음부터 해당 밸류값을 Date 타입으로도 받아오는 방법도 있습니다~! |
||
self.scheduleTitleLabel.text = model.title | ||
if let tagType = CalenderCategoryTagType(rawValue: model.type) { | ||
self.scheduleCategoryTagView.setData(title: tagType.text, | ||
|
Uh oh!
There was an error while loading. Please reload this page.