Skip to content

Commit

Permalink
refactor: use luxon instead of moment
Browse files Browse the repository at this point in the history
  • Loading branch information
trovster committed Jun 17, 2024
1 parent be39c89 commit 486b259
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/_filters/date.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const dateTime = require('moment')
const { DateTime } = require('luxon')

module.exports = (date, format) => {
return dateTime(date).format(format)
return DateTime.fromISO(date).toFormat(format)
}
6 changes: 3 additions & 3 deletions src/_layouts/game.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ layout: base.njk
<div class="event-post">
<h1>{{ title }}</h1>
<div class="datetime">
<p class="date">{{ date | date('ddd DD MMM') }}</p>
<p class="date">{{ date | date('ccc d LLLL') }}</p>
<p class="time">
<span class="starttime">{{ date | date("h:mma") }}</span>
<span class="endtime">–{{ endDate | date("h:mma") }}</span>
<span class="starttime">{{ date | date('h:mma') }}</span>
<span class="endtime">–{{ endDate | date('h:mma') }}</span>
</p>
</div>
<p class="subscribe">
Expand Down
6 changes: 3 additions & 3 deletions src/_layouts/games.njk
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ layout: base.njk
<tr class="vevent {{ 'past' if isPast(game) }}">
<td class="datetime">
{% if showDate(game.data.date, loop.index0, collections[tag]) %}
<span class="day">{{ game.data.date | date('ddd DD MMM') }}</span>
<span class="day">{{ game.data.date | date('ccc d LLLL') }}</span>
{% endif %}
<time class="dtstart">{{ game.data.date | date('YYYY-MM-DDTHH:mm:ssZ') }}</time>
<time class="dtend">{{ game.data.endDate | date('YYYY-MM-DDTHH:mm:ssZ') }}</time>
<time class="dtstart">{{ game.data.date | date("yyyy-LL-dd'T'HH:mm:ssZZZ") }}</time>
<time class="dtend">{{ game.data.endDate | date("yyyy-LL-dd'T'H:mm:ssZZZ") }}</time>
</td>
<td class="time">
<span>{{ game.data.date | date('H:mm') }}</span>
Expand Down
4 changes: 2 additions & 2 deletions src/_methods/IcalTemplate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const dateTime = require('moment')
const { DateTime } = require('luxon')
const absoluteUrl = require('../_filters/absoluteUrl')

module.exports = class
Expand All @@ -24,7 +24,7 @@ module.exports = class
}

date (date) {
return dateTime(date).format('YYYY-M-D-H-m').split('-').map(a => parseInt(a, 10))
return DateTime.fromISO(date).toFormat('y-LL-d-H-mm').split('-').map(a => parseInt(a, 10))
}

description (game) {
Expand Down
4 changes: 2 additions & 2 deletions src/_methods/showDate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const dateTime = require('moment')
const { DateTime } = require('luxon')

module.exports = (date, index, collection) => {
const prevIndex = index - 1
Expand All @@ -9,5 +9,5 @@ module.exports = (date, index, collection) => {

const prevDay = collection[prevIndex].data.date

return dateTime(prevDay).format('ddd DD MMM') !== dateTime(date).format('ddd DD MMM')
return DateTime.fromISO(prevDay).toLocaleString(DateTime.DATE_SHORT) !== DateTime.fromISO(date).toLocaleString(DateTime.DATE_SHORT)
}
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("DD MMM") }}{{ competition.end | date("DD MMM YYYY") }}</p>
<p>{{ competition.start | date('d LLLL') }}{{ competition.end | date('d LLLL yyyy') }}</p>
</a>
</li>
{% endfor %}
Expand Down

0 comments on commit 486b259

Please sign in to comment.