Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/code-sandbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"date-fns/08-month/getMonth": "https://codesandbox.io/s/jqquk?previewwindow=tests&file=/08-month/getMonth/vanilla.js",
"date-fns/08-month/isFirstDayOfMonth": "https://codesandbox.io/s/ltltp?previewwindow=tests&file=/08-month/isFirstDayOfMonth/vanilla.js",
"date-fns/08-month/isLastDayOfMonth": "https://codesandbox.io/s/d9veq?previewwindow=tests&file=/08-month/isLastDayOfMonth/vanilla.js",
"date-fns/08-month/lastDayOfMonth": "https://codesandbox.io/s/date-fns-lastdayofmonth-eun1ls?previewwindow=tests&file=/00-generic/compareDesc/vanilla.js",
"date-fns/08-month/isSameMonth": "https://codesandbox.io/s/04clz?previewwindow=tests&file=/08-month/isSameMonth/vanilla.js",
"date-fns/08-month/isThisMonth": "https://codesandbox.io/s/4u126?previewwindow=tests&file=/08-month/isThisMonth/vanilla.js",
"date-fns/08-month/setMonth": "https://codesandbox.io/s/jcvuk?previewwindow=tests&file=/08-month/setMonth/vanilla.js",
Expand Down
6 changes: 6 additions & 0 deletions src/content/date-fns/08-month/lastDayOfMonth/date-fns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// https://date-fns.org/v2.29.3/docs/lastDayOfMonth
const lastDayOfMonth = require('date-fns/lastDayOfMonth')

// Get the last day of a month.
module.exports = lastDayOfMonth(new Date(2014, 1, 25)).toDateString()
// => Fri Feb 28 2014
1 change: 1 addition & 0 deletions src/content/date-fns/08-month/lastDayOfMonth/notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Get the last day of a month from date.
9 changes: 9 additions & 0 deletions src/content/date-fns/08-month/lastDayOfMonth/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const expected = 'Fri Feb 28 2014'

const datefns = require('./date-fns')
const plain = require('./vanilla')

test('lastDayOfMonth', () => {
expect(datefns).toEqual(expected)
expect(plain).toEqual(datefns)
})
13 changes: 13 additions & 0 deletions src/content/date-fns/08-month/lastDayOfMonth/vanilla.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function lastDayOfMonth(date) {
const dateClone = new Date(date.getTime())
const month = dateClone.getMonth()
dateClone.setDate(1)
dateClone.setMonth(month + 1)
dateClone.setDate(0)

return dateClone
}

// Get the last day of a month.
module.exports = lastDayOfMonth(new Date(2014, 1, 25)).toDateString()
// => Fri Feb 28 2014