Skip to content

Commit

Permalink
๐Ÿ”€ย :: (#519) notificationList bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
juyeong525 authored Jun 3, 2023
2 parents 90c50f7 + 96a0719 commit 7b8f85c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct NotificationListCell: View {
.sdText(type: .caption2)

Spacer()
Text(getTimeForSend(date: entity.sendAt))
Text(entity.sendAt.getTimeAgoAsKoreanString())
.sdText(type: .caption2)
}
Text(entity.content)
Expand All @@ -33,34 +33,18 @@ struct NotificationListCell: View {
.padding(16)
.background(entity.isRead ? .white : .GrayScale.gray50)
}

private func getTimeForSend(date: Date) -> String {
let today = Date()

if Int(today.toString(format: "MM")) ?? 0 > Int(date.toString(format: "MM")) ?? 0 {
return "\((Int(today.toString(format: "MM")) ?? 0) - (Int(date.toString(format: "MM")) ?? 0))๋‹ฌ ์ „"
} else if Int(today.toString(format: "dd")) ?? 0 > Int(date.toString(format: "dd")) ?? 0 {
return "\((Int(today.toString(format: "dd")) ?? 0) - (Int(date.toString(format: "dd")) ?? 0))์ผ ์ „"
} else if Int(today.toString(format: "HH")) ?? 0 > Int(date.toString(format: "HH")) ?? 0 {
return "\((Int(today.toString(format: "HH")) ?? 0) - (Int(date.toString(format: "HH")) ?? 0))์‹œ๊ฐ„ ์ „"
} else if Int(today.toString(format: "mm")) ?? 0 > Int(date.toString(format: "mm")) ?? 0 {
return "\((Int(today.toString(format: "mm")) ?? 0) - (Int(date.toString(format: "mm")) ?? 0))๋ถ„ ์ „"
} else {
return "๋ฐฉ๊ธˆ ์ „"
}
}
// swiftlint:disable line_length
private func topicToImage(topic: NotificationTopic) -> Image {
switch topic {
case .applicationWeekendMeal, .applicationStay, .applicationMoveClassRoom, .applicationPicnic, .applicationPicnicPass, .applicationWeekendPicnic, .applicationWeekendPicnicReservation:
return Image.application
case .allGoodPoint:
case .allGoodPoint, .feedBambooLike, .feedNoticeLike:
return Image.thumbUpNotiIcon
case .allBadPoint, .allPenaltyLevel:
return Image.thumbDownNotiIcon
case .scheduleLocal, .scheduleSocial:
return Image.calendar
case .feedNotice, .feedBambooLike, .feedNoticeLike, .feedBambooComment, .feedNoticeComment:
case .feedNotice, .feedBambooComment, .feedNoticeComment:
return Image.feed
}
}
Expand Down
35 changes: 35 additions & 0 deletions Modules/XDateUtil/Sources/DateToString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,39 @@ public extension Date {
return XDateFormatter.shared.string(from: self)
}

func getTimeAgoAsKoreanString() -> String {
var resultMinute = Calendar.current.dateComponents([.minute], from: self, to: .now).minute!
if resultMinute / 60 == 0 && resultMinute % 60 == 0 {
return "๋ฐฉ๊ธˆ ์ „"
} else if resultMinute / 60 == 0 {
return "\(resultMinute % 60)๋ถ„ ์ „"
} else if resultMinute / 60 / 24 == 0 {
return "\(resultMinute / 60 % 24)์‹œ๊ฐ„ ์ „"
} else {
resultMinute = resultMinute / 60 / 24
let toDay = Calendar.current.dateComponents([.year, .month, .day], from: .now)
let sendAt = Calendar.current.dateComponents([.year, .month, .day], from: self)
if (toDay.day! - sendAt.day! < 0 && toDay.month! == sendAt.month! + 1) || sendAt.month == toDay.month {
return "\(resultMinute)์ผ ์ „"
} else {
let yearDifference = (toDay.year! - sendAt.year!) * 12
for time in sendAt.month!..<toDay.month! + yearDifference {
if time % 12 == 0 {
resultMinute -= 12.monthToDate(date: self)
} else {
resultMinute -= time%12.monthToDate(date: self)
}
}
if resultMinute >= 1 {
if toDay.month! + yearDifference - sendAt.month! >= 12 {
return "\((toDay.month! + yearDifference - sendAt.month!) / 12)๋…„ ์ „"
} else {
return "\(toDay.month! + yearDifference - sendAt.month!)๋‹ฌ ์ „"
}
} else {
return "\(toDay.month! + yearDifference - sendAt.month! - 1)๋‹ฌ ์ „"
}
}
}
}
}
18 changes: 18 additions & 0 deletions Modules/XDateUtil/Sources/monthToDay.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation

extension Int {
func monthToDate(date: Date) -> Int {
switch self {
case 1, 3, 5, 7, 8, 10, 12:
return 31
case 4, 6, 9, 11:
return 30
default:
if Calendar.current.dateComponents([.year], from: date).isLeapMonth! {
return 29
} else {
return 28
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension NotificationResponse {
id: id,
title: title,
content: content,
sendAt: sendAt.toDate(format: .fullDateWithTime),
sendAt: sendAt.toDate(format: .fullDateWithMilliSecondTime),
isRead: isRead,
userId: userId,
topic: .init(rawValue: topic) ?? .allGoodPoint
Expand Down

0 comments on commit 7b8f85c

Please sign in to comment.