Skip to content

Commit

Permalink
[fix] dateform 함수 -> util패키지 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryeolee committed May 4, 2024
1 parent b7b1291 commit 9192bea
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

import static com.modernfarmer.farmusspring.domain.myveggiegarden.util.DateManager.formatDate;

@AllArgsConstructor
@NoArgsConstructor
@Getter
Expand All @@ -34,11 +32,6 @@ public static List<AllDairy> processData(List<Diary> diaryList){
.map(diary -> AllDairy.of(diary, formatDate(diary.getCreatedDate())))
.toList();
}
public static String formatDate(LocalDateTime date) {

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy년 MM월 dd일");
String formattedDate = date.format(formatter);
return formattedDate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public List<MyDetailMyVeggie> processData(List<MyVeggie> myVeggieList){
myVeggie.getNickname(),
myVeggie.getVeggieImage(),
myVeggie.getVeggieName(),
dateManager.dateParsing(myVeggie.getBirth()),
dateManager.dayBetween(myVeggie.getBirth(), new Date()),
dateManager.parsingDotDate(myVeggie.getBirth()),
dateManager.calculateDay(myVeggie.getBirth(), new Date()),
myVeggie.getId()

)).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Getter
public class SelectMyVeggieListDto {

public List<SelectMyVeggieListResponse> processData(List<MyVeggie> myVeggieList){
public static List<SelectMyVeggieListResponse> processData(List<MyVeggie> myVeggieList){
return myVeggieList.stream()
.map(myVeggie -> SelectMyVeggieListResponse.of(myVeggie.getVeggieInfoId(),myVeggie.getNickname()))
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MyVeggieGardenService {
private final MyVeggieRepository myVeggieRepository;
private final DateManager dateManager;
private final MyDetailMyVeggieDto myDetailMyVeggieDto;
private final SelectMyVeggieListDto selectMyVeggieListDto;



@Transactional
Expand All @@ -40,7 +40,7 @@ public BaseResponseDto<Void> settingMyVeggie(Long userId, SettingMyVeggieRequest
@Transactional
public BaseResponseDto<List<SelectMyVeggieListResponse>> selectMyVeggieList(Long userId) {
List<MyVeggie> myVeggieList = bringMyVeggieData(userId);
List<SelectMyVeggieListResponse> selectMyVeggieLists = selectMyVeggieListDto.processData(myVeggieList);
List<SelectMyVeggieListResponse> selectMyVeggieLists = SelectMyVeggieListDto.processData(myVeggieList);
return BaseResponseDto.of(SuccessCode.SUCCESS,selectMyVeggieLists);
}

Expand All @@ -57,8 +57,8 @@ public BaseResponseDto<SelectMyVeggieProfileResponse> selectMyVeggieProfile(Long
SelectMyVeggieProfileResponse.of(
myVeggie.getVeggieName(),
myVeggie.getVeggieImage(),
dateManager.dateParsing(myVeggie.getBirth()),
dateManager.dayBetween(myVeggie.getBirth(), new Date()),
dateManager.parsingDotDate(myVeggie.getBirth()),
dateManager.calculateDay(myVeggie.getBirth(), new Date()),
checkFarmClubAffiliation(myVeggie)
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;


@Component
public class DateManager {

public String dateParsing(Date date){
public String parsingDotDate(Date date){
SimpleDateFormat format = new SimpleDateFormat("yy.MM.dd");
return format.format(date);
}
public int dayBetween(Date startDate, Date endDate) {
public int calculateDay(Date startDate, Date endDate) {
long differenceMillis = endDate.getTime() - startDate.getTime();
long differenceDays = differenceMillis / (1000 * 60 * 60 * 24);
return (int) differenceDays;
}

public static String formatDate(LocalDateTime date) {

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy년 MM월 dd일");
String formattedDate = date.format(formatter);
return formattedDate;
}

}

0 comments on commit 9192bea

Please sign in to comment.