-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add date-range-text to report week graph
- Loading branch information
Showing
9 changed files
with
100 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/de/focusshift/zeiterfassung/user/DateRangeFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package de.focusshift.zeiterfassung.user; | ||
|
||
import org.springframework.context.MessageSource; | ||
import org.springframework.context.i18n.LocaleContextHolder; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Locale; | ||
|
||
@Component | ||
public class DateRangeFormatter { | ||
|
||
private final DateFormatter dateFormatter; | ||
private final MessageSource messageSource; | ||
|
||
DateRangeFormatter(DateFormatter dateFormatter, MessageSource messageSource) { | ||
this.dateFormatter = dateFormatter; | ||
this.messageSource = messageSource; | ||
} | ||
|
||
public String toDateRangeString(LocalDate from, LocalDate to) { | ||
|
||
final MonthFormat firstMonthFormat = | ||
from.getMonthValue() == to.getMonthValue() ? MonthFormat.NONE : MonthFormat.STRING; | ||
|
||
final YearFormat firstYearFormat = | ||
from.getYear() == to.getYear() ? YearFormat.NONE : YearFormat.FULL; | ||
|
||
final String firstDateString = dateFormatter.formatDate(from, firstMonthFormat, firstYearFormat); | ||
final String lastDateString = dateFormatter.formatDate(to, MonthFormat.STRING, YearFormat.FULL); | ||
|
||
return messageSource.getMessage("date-range", new Object[]{firstDateString, lastDateString}, locale()); | ||
} | ||
|
||
private Locale locale() { | ||
return LocaleContextHolder.getLocale(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters