Skip to content

Commit

Permalink
fix: add ordinal to dates
Browse files Browse the repository at this point in the history
  • Loading branch information
trovster committed Aug 20, 2024
1 parent 46c7899 commit f26aafa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/_filters/date.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const { DateTime } = require('luxon')

module.exports = (date, format) => {
return DateTime.fromISO(date).toFormat(format)
function ordinal (n) {
const s = ['th', 'st', 'nd', 'rd']
const v = n % 100
return "'" + n + (s[(v - 20) % 10] || s[v] || s[0]) + "' "
}

module.exports = (date, format, locale = 'en') => {
date = DateTime.fromISO(date).setLocale(locale)
return date.toFormat(format.replace('dS ', ordinal(date.day)))
}
2 changes: 1 addition & 1 deletion src/_layouts/game.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ layout: base.njk
<h1 class="p-name">{{ title }}</h1>

<div class="datetime">
<p class="date">{{ date | date('ccc d LLLL') }}</p>
<p class="date">{{ date | date('ccc dS LLLL') }}</p>
<p class="time">
<span class="starttime">{{ date | date('h:mma') }}</span>
<span class="endtime">–{{ endDate | date('h:mma') }}</span>
Expand Down
2 changes: 1 addition & 1 deletion src/_layouts/games.njk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ layout: base.njk
<tr class="vevent h-event">
<td class="datetime">
{% if showDate(game.data.date, loop.index0, collections[tag]) %}
<span class="day">{{ game.data.date | date('ccc d LLLL') }}</span>
<span class="day">{{ game.data.date | date('ccc dS LLLL') }}</span>
{% endif %}
</td>
<td class="time">
Expand Down
2 changes: 1 addition & 1 deletion src/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ title: Football times in your calendar
<li>
<a href="{{ competition.path | url | absoluteUrl(config.baseUrl) }}">
<h2>{{ competition.title }}</h2>
<p>{{ competition.start | date('d LLLL') }}{{ competition.end | date('d LLLL yyyy') }}</p>
<p>{{ competition.start | date('dS LLLL') }}{{ competition.end | date('dS LLLL yyyy') }}</p>
</a>
</li>
{% endfor %}
Expand Down

0 comments on commit f26aafa

Please sign in to comment.