Merge pull request #383 from kolplattformen/feature/no-year-if-same-year

style: 💄 Calendar date - remove year if current year
This commit is contained in:
Viktor Sarström 2021-05-11 09:38:51 +02:00 committed by GitHub
commit 899ac06f52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -22,6 +22,17 @@ export const Calendar = () => {
const { data } = useCalendar(child)
const styles = useStyleSheet(themedStyles)
const formatStartDate = (startDate: moment.MomentInput) => {
const date = moment(startDate)
const output = `${date.format('dddd')} ${date.format(
'll'
)} ${date.fromNow()}`
// Hack to remove yarn if it is this year
const currentYear = moment().year().toString(10)
return output.replace(currentYear, '')
}
return (
<View style={styles.container}>
<Week child={child} />
@ -39,9 +50,7 @@ export const Calendar = () => {
title={`${item.title}`}
description={(props) => (
<Text style={[props?.style, styles.description]}>
{`${moment(item.startDate).format('dddd')} ${moment(
item.startDate
).format('ll')} (${moment(item.startDate).fromNow()})`}
{formatStartDate(item.startDate)}
</Text>
)}
accessoryLeft={CalendarOutlineIcon}