Skip to content

Commit

Permalink
feat(api): add year(), month()
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Apr 11, 2018
1 parent 49bd2c2 commit db66598
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class Dayjs {
return false
}

year() {
return this.date.getFullYear()
}

month() {
return this.date.getMonth()
}

unix() {
const zonePad = this.utc ? this.date.getTimezoneOffset() * 60 * 1000 : 0
return Math.floor((this.date.getTime() + zonePad) / 1000)
Expand Down
11 changes: 11 additions & 0 deletions test/get-set.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import moment from 'moment'
import dayjs from '../src'

test('Year', () => {
expect(dayjs().year()).toBe(moment().year())
})

test('Month', () => {
expect(dayjs().month()).toBe(moment().month())
})

0 comments on commit db66598

Please sign in to comment.