Skip to content

Commit

Permalink
fix: utcOffset, when offset has minutes <> '0' or '30'
Browse files Browse the repository at this point in the history
Example for offset not full or halve hours is '1879-12-31' for
timezone 'Europe/Berlin', where utcOffset is '00:53'.
Solves issue iamkun#1996.
  • Loading branch information
BePo65 committed Aug 24, 2022
1 parent fbf5553 commit 357df18
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- accessing get / set with unit string (e.g. "`dayjs().get('year')`") takes short form of units too (allowed values are 'y', 'M', 'D', 'h', 'm', 's', 'ms').
- unlike 'moment': Day of Week is accessible by name ('D' / 'day') too.
- unlike 'moment': the **unit names are case sensitive**.
- make utcOffset() behave like 'moment' (rounding away only the fractional part of the minutes - i.e. the seconds - and not the minutes to a quarter of an hour).

---

Expand Down
5 changes: 2 additions & 3 deletions src/dayjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,8 @@ export class Dayjs extends (class {} as Extend) {
}

utcOffset() {
// Because a bug at FF24, we're rounding the timezone offset around 15 minutes
// https://github.com/moment/moment/pull/1871
return -Math.round(this._d.getTimezoneOffset() / 15) * 15
// Remove fractional part (seconds) from offset (just like moment.js does)
return -Math.round(this._d.getTimezoneOffset())
}

format(formatStr?: string) {
Expand Down

0 comments on commit 357df18

Please sign in to comment.