Skip to content

Commit

Permalink
Merge pull request #97 from ku-ring/fix/dept_notice_date_format
Browse files Browse the repository at this point in the history
kuring-136 바뀐 학과별 공지 날짜 포맷 대응
  • Loading branch information
mwy3055 authored Feb 28, 2024
2 parents 96ebee6 + 6326f03 commit 1b1c528
Showing 1 changed file with 2 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.ku_stacks.ku_ring.notice.mapper

import com.ku_stacks.ku_ring.local.entity.NoticeEntity
import com.ku_stacks.ku_ring.remote.notice.response.DepartmentNoticeResponse
import java.text.SimpleDateFormat
import java.util.Locale


fun List<DepartmentNoticeResponse>.toEntityList(shortName: String, startDate: String) =
Expand All @@ -14,24 +12,16 @@ fun List<DepartmentNoticeResponse>.toEntityList(shortName: String, startDate: St
* TODO: NPE 대신 빈 문자열을 넣도록 수정
*/
fun DepartmentNoticeResponse.toNoticeEntity(shortName: String, startDate: String): NoticeEntity {
val dashRemovedPostedDate = removeDashFromDate(postedDate!!)
return NoticeEntity(
articleId = articleId!!,
category = category!!,
department = shortName,
subject = subject!!,
postedDate = dashRemovedPostedDate,
postedDate = postedDate!!,
url = url!!,
isNew = (dashRemovedPostedDate >= startDate),
isNew = (postedDate!! >= startDate),
isRead = false,
isSaved = false,
isReadOnStorage = false,
)
}

private fun removeDashFromDate(dashSeparatedDate: String): String {
val inputFormatter = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
val outputFormatter = SimpleDateFormat("yyyyMMdd", Locale.getDefault())
val date = inputFormatter.parse(dashSeparatedDate)
return outputFormatter.format(date)
}

0 comments on commit 1b1c528

Please sign in to comment.