|  | 
| 1 | 1 | /* eslint-disable no-bitwise, no-multi-assign */ | 
|  | 2 | +import toDate from 'date-fns-tz/toDate'; | 
| 2 | 3 | import defaultLocales from './defaults/locales'; | 
| 3 | 4 | import { pad, addPages, pageForDate, arrayHasItems } from './helpers'; | 
| 4 | 5 | import { | 
| @@ -492,47 +493,51 @@ export default class Locale { | 
| 492 | 493 |     return parts; | 
| 493 | 494 |   } | 
| 494 | 495 | 
 | 
| 495 |  | -  getDateFromParts(parts, timezone) { | 
|  | 496 | +  getDateFromParts(parts, timeZone) { | 
| 496 | 497 |     if (!parts) return null; | 
| 497 | 498 |     const { | 
| 498 | 499 |       year: y, | 
| 499 | 500 |       month: m, | 
| 500 | 501 |       day: d, | 
| 501 |  | -      hours: hrs, | 
| 502 |  | -      minutes: min, | 
| 503 |  | -      seconds: sec, | 
| 504 |  | -      milliseconds: ms, | 
|  | 502 | +      hours: hrs = 0, | 
|  | 503 | +      minutes: min = 0, | 
|  | 504 | +      seconds: sec = 0, | 
|  | 505 | +      milliseconds: ms = 0, | 
| 505 | 506 |     } = parts; | 
| 506 | 507 |     if (y === undefined || m === undefined || d === undefined) return null; | 
| 507 |  | -    const utcDate = new Date( | 
| 508 |  | -      Date.UTC(y || 0, m - 1, d || 0, hrs || 0, min || 0, sec || 0, ms || 0), | 
| 509 |  | -    ); | 
| 510 |  | -    const tzOffsetMs = this.getTimezoneOffset(parts, timezone); | 
| 511 |  | -    return new Date(utcDate.getTime() + tzOffsetMs); | 
|  | 508 | + | 
|  | 509 | +    if (timeZone) { | 
|  | 510 | +      const dateString = `${pad(y, 4)}-${pad(m, 2)}-${pad(d, 2)}T${pad( | 
|  | 511 | +        hrs, | 
|  | 512 | +        2, | 
|  | 513 | +      )}:${pad(min, 2)}:${pad(sec, 2)}.${pad(ms, 3)}`; | 
|  | 514 | +      return toDate(dateString, { timeZone }); | 
|  | 515 | +    } | 
|  | 516 | +    return new Date(y, m - 1, d, hrs, min, sec, ms); | 
| 512 | 517 |   } | 
| 513 | 518 | 
 | 
| 514 |  | -  getTimezoneOffset(parts, timezone) { | 
|  | 519 | +  getTimezoneOffset(parts, timeZone) { | 
| 515 | 520 |     const { | 
| 516 | 521 |       year: y, | 
| 517 | 522 |       month: m, | 
| 518 | 523 |       day: d, | 
| 519 |  | -      minutes: min, | 
| 520 |  | -      seconds: sec, | 
| 521 |  | -      milliseconds: ms, | 
|  | 524 | +      hours: hrs = 0, | 
|  | 525 | +      minutes: min = 0, | 
|  | 526 | +      seconds: sec = 0, | 
|  | 527 | +      milliseconds: ms = 0, | 
| 522 | 528 |     } = parts; | 
| 523 |  | -    const formatter = new Intl.DateTimeFormat('en-US', { | 
| 524 |  | -      hour: 'numeric', | 
| 525 |  | -      hour12: false, | 
| 526 |  | -      hourCycle: 'h24', | 
| 527 |  | -      timeZone: timezone || undefined, | 
| 528 |  | -    }); | 
| 529 |  | -    const utcNoon = new Date( | 
| 530 |  | -      Date.UTC(y || 0, m - 1, d || 0, 12, min || 0, sec || 0, ms || 0), | 
| 531 |  | -    ); | 
| 532 |  | -    const tzHours = +formatter.format(utcNoon); | 
| 533 |  | -    const tzOffset = 12 - tzHours; | 
| 534 |  | -    const msInHour = 3600000; | 
| 535 |  | -    return tzOffset * msInHour; | 
|  | 529 | +    let date; | 
|  | 530 | +    const utcDate = new Date(Date.UTC(y, m - 1, d, hrs, min, sec, ms)); | 
|  | 531 | +    if (timeZone) { | 
|  | 532 | +      const dateString = `${pad(y, 4)}-${pad(m, 2)}-${pad(d, 2)}T${pad( | 
|  | 533 | +        hrs, | 
|  | 534 | +        2, | 
|  | 535 | +      )}:${pad(min, 2)}:${pad(sec, 2)}.${pad(ms, 3)}`; | 
|  | 536 | +      date = toDate(dateString, { timeZone }); | 
|  | 537 | +    } else { | 
|  | 538 | +      date = new Date(y, m - 1, d, hrs, min, sec, ms); | 
|  | 539 | +    } | 
|  | 540 | +    return utcDate - date; | 
| 536 | 541 |   } | 
| 537 | 542 | 
 | 
| 538 | 543 |   toPage(arg, fromPage) { | 
|  | 
0 commit comments