├── .github └── workflows │ └── publish.yml ├── .gitignore ├── .npmignore ├── LICENSE.md ├── README.md ├── builds └── cdn.js ├── dist ├── alpine-timeago.js ├── alpine-timeago.js.map ├── alpine-timeago.min.js └── alpine-timeago.min.js.map ├── examples └── index.html ├── package.json ├── rollup.config.js └── src └── index.js /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | update-dist: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | - uses: actions/setup-node@v1 13 | with: 14 | node-version: ^16.0.0 15 | - run: npm install 16 | - run: npm run build 17 | - uses: stefanzweifel/git-auto-commit-action@v4 18 | with: 19 | commit_message: 📦 Update compiled files 20 | file_pattern: dist/**/* 21 | publish-npm: 22 | runs-on: ubuntu-latest 23 | steps: 24 | - uses: actions/checkout@v2 25 | - uses: actions/setup-node@v1 26 | with: 27 | node-version: ^16.0.0 28 | registry-url: https://registry.npmjs.org/ 29 | - name: Check package version 30 | uses: technote-space/package-version-check-action@v1 31 | with: 32 | COMMIT_DISABLED: 1 33 | - run: npm install 34 | - run: npm run build 35 | - run: npm publish --access public 36 | env: 37 | NODE_AUTH_TOKEN: ${{ secrets.npm_token }} 38 | publish-github: 39 | runs-on: ubuntu-latest 40 | steps: 41 | - uses: actions/checkout@v2 42 | - uses: actions/setup-node@v1 43 | with: 44 | node-version: ^16.0.0 45 | - name: Check package version 46 | uses: technote-space/package-version-check-action@v1 47 | with: 48 | COMMIT_DISABLED: 1 49 | - run: npm install 50 | - run: npm run build 51 | - uses: actions/setup-node@v2 52 | with: 53 | node-version: ^16.0.0 54 | registry-url: https://npm.pkg.github.com/ 55 | - run: npm publish 56 | env: 57 | NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 58 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /.idea 3 | *.tgz 4 | package-lock.json 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | builds 3 | .github 4 | .idea 5 | rollup.config.js 6 | *.tgz 7 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Marc Reichel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

⏱ Alpine TimeAgo ⏱

2 | 3 |

4 | An Alpine.js plugin to return the distance between a given date and now in words (like "3 months ago", "about 2 hours ago" or "in about 5 hours"). 5 |

6 | 7 |

8 | 9 | version 10 | 11 | 12 | Build size 13 | 14 | 15 | downloads 16 | 17 | 18 | JSDelivr 19 | 20 | 21 | GitHub 22 | 23 | 24 | Gitmoji 25 | 26 |

27 | 28 | ## 🚀 Installation 29 | 30 | ### CDN 31 | 32 | Include the following ` 36 | ``` 37 | 38 | ### NPM 39 | 40 | ```shell 41 | npm install @marcreichel/alpine-timeago 42 | ``` 43 | 44 | Add the `x-timeago` directive to your project by importing the package **before** starting Alpine. 45 | 46 | ```js 47 | import Alpine from 'alpinejs'; 48 | import TimeAgo from '@marcreichel/alpine-timeago'; 49 | 50 | Alpine.plugin(TimeAgo); 51 | 52 | Alpine.start(); 53 | ``` 54 | 55 | ## 🪄 Usage 56 | 57 | ### Directive 58 | 59 | To convert a Date to the human-readable distance from now, add the `x-data` and `x-timeago` directives to an element and 60 | pass the date (as a `Date` or a string in ISO format) to the `x-timeago` directive. The directive will update the output 61 | every 30 seconds. 62 | 63 | ```html 64 | 65 | ``` 66 | 67 | Under the hood the directive is using [`formatDistanceToNow`](https://date-fns.org/v2.28.0/docs/formatDistanceToNow) 68 | from `date-fns`. 69 | 70 | #### No suffix 71 | 72 | If you do not want the "[diff] ago" suffix or "in [diff]" prefix, you can use the `x-timeago.pure` modifier. 73 | 74 | ```html 75 | 76 | ``` 77 | 78 | #### Include seconds 79 | 80 | Distances less than a minute are more detailed. 81 | 82 | ```html 83 | 84 | ``` 85 | 86 | ### Strict 87 | 88 | If you do not want the "about [diff]" or "less than [diff]" prefixes, you can use the `x-timeago.strict` modifier. 89 | 90 | ```html 91 | 92 | ``` 93 | 94 | #### Strict options 95 | 96 | The strict mode comes with its own set of modifiers for controlling the output. 97 | 98 | ##### Force unit 99 | 100 | Use the `x-timeago.strict.unit.[unit]` modifier with one of the following units to force the unit in the output. 101 | 102 | - `second` (e.g. `x-timeago.strict.unit.second`) 103 | - `minute` (e.g. `x-timeago.strict.unit.minute`) 104 | - `hour` (e.g. `x-timeago.strict.unit.hour`) 105 | - `day` (e.g. `x-timeago.strict.unit.day`) 106 | - `month` (e.g. `x-timeago.strict.unit.month`) 107 | - `year` (e.g. `x-timeago.strict.unit.year`) 108 | 109 | ##### Adjust rounding method 110 | 111 | By default, the values are rounded using the `Math.round` algorithm. If you would like to adjust this, use 112 | the `x-timeago.rounding.[method]` modifier with one of the following methods: 113 | 114 | - `floor` (e.g. `x-timeago.strict.rounding.floor`) 115 | - `ceil` (e.g. `x-timeago.strict.rounding.ceil`) 116 | - `floor` (e.g. `x-timeago.strict.rounding.round`) 117 | 118 | ### Magic function 119 | 120 | As of version 1.3.0 of this package a `$timeago` magic function is included which will return the human-readable 121 | distance from now. 122 | 123 | ```html 124 | 125 | ``` 126 | 127 | > **Note**: Using the magic function the distance does not get updated automatically. You have to update it yourself if 128 | > you want to. 129 | 130 | #### No suffix 131 | 132 | If you do not want the "[diff] ago" suffix or "in [diff]" prefix, you can provide `true` as the second parameter to the 133 | function. 134 | 135 | ```html 136 | 137 | ``` 138 | 139 | #### Include seconds 140 | 141 | If you want distances less than a minute to be more detailed, you can provide `true` as the third parameter to the 142 | function. 143 | 144 | ```html 145 | 146 | ``` 147 | 148 | #### Strict 149 | 150 | If you do not want the "about [diff]" or "less than [diff]" prefixes, you can use the fourth parameter to provide the " 151 | strict" options. 152 | 153 | ##### Default 154 | 155 | ```html 156 | 158 | ``` 159 | 160 | ##### Unit 161 | 162 | ```html 163 | 165 | ``` 166 | 167 | ##### Rounding method 168 | 169 | ```html 170 | 172 | ``` 173 | 174 | ### Other locales 175 | 176 | If you are using the `npm` installation method for this package or the ESM distribution, you can use the 177 | `TimeAgo.configure()` method to provide a different locale from `date-fns`. 178 | 179 | ```javascript 180 | import TimeAgo from '@marcreichel/alpine-timeago'; 181 | import {de} from 'date-fns/locale'; 182 | 183 | Alpine.plugin(TimeAgo.configure({ 184 | locale: de, 185 | })); 186 | ``` 187 | 188 | ## 📄 License 189 | 190 | Copyright (c) 2022 Marc Reichel and contributors. 191 | 192 | Licensed under the MIT license, see [LICENSE](LICENSE) for details. 193 | -------------------------------------------------------------------------------- /builds/cdn.js: -------------------------------------------------------------------------------- 1 | import TimeAgo from '../src/index.js'; 2 | 3 | document.addEventListener('alpine:init', () => { 4 | TimeAgo(window.Alpine); 5 | }); 6 | -------------------------------------------------------------------------------- /dist/alpine-timeago.js: -------------------------------------------------------------------------------- 1 | (function (factory) { 2 | typeof define === 'function' && define.amd ? define(factory) : 3 | factory(); 4 | })((function () { 'use strict'; 5 | 6 | function requiredArgs(required, args) { 7 | if (args.length < required) { 8 | throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present'); 9 | } 10 | } 11 | 12 | /** 13 | * @name toDate 14 | * @category Common Helpers 15 | * @summary Convert the given argument to an instance of Date. 16 | * 17 | * @description 18 | * Convert the given argument to an instance of Date. 19 | * 20 | * If the argument is an instance of Date, the function returns its clone. 21 | * 22 | * If the argument is a number, it is treated as a timestamp. 23 | * 24 | * If the argument is none of the above, the function returns Invalid Date. 25 | * 26 | * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`. 27 | * 28 | * @param {Date|Number} argument - the value to convert 29 | * @returns {Date} the parsed date in the local time zone 30 | * @throws {TypeError} 1 argument required 31 | * 32 | * @example 33 | * // Clone the date: 34 | * const result = toDate(new Date(2014, 1, 11, 11, 30, 30)) 35 | * //=> Tue Feb 11 2014 11:30:30 36 | * 37 | * @example 38 | * // Convert the timestamp to date: 39 | * const result = toDate(1392098430000) 40 | * //=> Tue Feb 11 2014 11:30:30 41 | */ 42 | 43 | function toDate(argument) { 44 | requiredArgs(1, arguments); 45 | var argStr = Object.prototype.toString.call(argument); // Clone the date 46 | 47 | if (argument instanceof Date || typeof argument === 'object' && argStr === '[object Date]') { 48 | // Prevent the date to lose the milliseconds when passed to new Date() in IE10 49 | return new Date(argument.getTime()); 50 | } else if (typeof argument === 'number' || argStr === '[object Number]') { 51 | return new Date(argument); 52 | } else { 53 | if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') { 54 | // eslint-disable-next-line no-console 55 | console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule"); // eslint-disable-next-line no-console 56 | 57 | console.warn(new Error().stack); 58 | } 59 | 60 | return new Date(NaN); 61 | } 62 | } 63 | 64 | /** 65 | * @name compareAsc 66 | * @category Common Helpers 67 | * @summary Compare the two dates and return -1, 0 or 1. 68 | * 69 | * @description 70 | * Compare the two dates and return 1 if the first date is after the second, 71 | * -1 if the first date is before the second or 0 if dates are equal. 72 | * 73 | * ### v2.0.0 breaking changes: 74 | * 75 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 76 | * 77 | * @param {Date|Number} dateLeft - the first date to compare 78 | * @param {Date|Number} dateRight - the second date to compare 79 | * @returns {Number} the result of the comparison 80 | * @throws {TypeError} 2 arguments required 81 | * 82 | * @example 83 | * // Compare 11 February 1987 and 10 July 1989: 84 | * const result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10)) 85 | * //=> -1 86 | * 87 | * @example 88 | * // Sort the array of dates: 89 | * const result = [ 90 | * new Date(1995, 6, 2), 91 | * new Date(1987, 1, 11), 92 | * new Date(1989, 6, 10) 93 | * ].sort(compareAsc) 94 | * //=> [ 95 | * // Wed Feb 11 1987 00:00:00, 96 | * // Mon Jul 10 1989 00:00:00, 97 | * // Sun Jul 02 1995 00:00:00 98 | * // ] 99 | */ 100 | 101 | function compareAsc(dirtyDateLeft, dirtyDateRight) { 102 | requiredArgs(2, arguments); 103 | var dateLeft = toDate(dirtyDateLeft); 104 | var dateRight = toDate(dirtyDateRight); 105 | var diff = dateLeft.getTime() - dateRight.getTime(); 106 | 107 | if (diff < 0) { 108 | return -1; 109 | } else if (diff > 0) { 110 | return 1; // Return 0 if diff is 0; return NaN if diff is NaN 111 | } else { 112 | return diff; 113 | } 114 | } 115 | 116 | /** 117 | * @name differenceInCalendarMonths 118 | * @category Month Helpers 119 | * @summary Get the number of calendar months between the given dates. 120 | * 121 | * @description 122 | * Get the number of calendar months between the given dates. 123 | * 124 | * ### v2.0.0 breaking changes: 125 | * 126 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 127 | * 128 | * @param {Date|Number} dateLeft - the later date 129 | * @param {Date|Number} dateRight - the earlier date 130 | * @returns {Number} the number of calendar months 131 | * @throws {TypeError} 2 arguments required 132 | * 133 | * @example 134 | * // How many calendar months are between 31 January 2014 and 1 September 2014? 135 | * var result = differenceInCalendarMonths( 136 | * new Date(2014, 8, 1), 137 | * new Date(2014, 0, 31) 138 | * ) 139 | * //=> 8 140 | */ 141 | 142 | function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) { 143 | requiredArgs(2, arguments); 144 | var dateLeft = toDate(dirtyDateLeft); 145 | var dateRight = toDate(dirtyDateRight); 146 | var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear(); 147 | var monthDiff = dateLeft.getMonth() - dateRight.getMonth(); 148 | return yearDiff * 12 + monthDiff; 149 | } 150 | 151 | /** 152 | * @name endOfDay 153 | * @category Day Helpers 154 | * @summary Return the end of a day for the given date. 155 | * 156 | * @description 157 | * Return the end of a day for the given date. 158 | * The result will be in the local timezone. 159 | * 160 | * ### v2.0.0 breaking changes: 161 | * 162 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 163 | * 164 | * @param {Date|Number} date - the original date 165 | * @returns {Date} the end of a day 166 | * @throws {TypeError} 1 argument required 167 | * 168 | * @example 169 | * // The end of a day for 2 September 2014 11:55:00: 170 | * const result = endOfDay(new Date(2014, 8, 2, 11, 55, 0)) 171 | * //=> Tue Sep 02 2014 23:59:59.999 172 | */ 173 | 174 | function endOfDay(dirtyDate) { 175 | requiredArgs(1, arguments); 176 | var date = toDate(dirtyDate); 177 | date.setHours(23, 59, 59, 999); 178 | return date; 179 | } 180 | 181 | /** 182 | * @name endOfMonth 183 | * @category Month Helpers 184 | * @summary Return the end of a month for the given date. 185 | * 186 | * @description 187 | * Return the end of a month for the given date. 188 | * The result will be in the local timezone. 189 | * 190 | * ### v2.0.0 breaking changes: 191 | * 192 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 193 | * 194 | * @param {Date|Number} date - the original date 195 | * @returns {Date} the end of a month 196 | * @throws {TypeError} 1 argument required 197 | * 198 | * @example 199 | * // The end of a month for 2 September 2014 11:55:00: 200 | * const result = endOfMonth(new Date(2014, 8, 2, 11, 55, 0)) 201 | * //=> Tue Sep 30 2014 23:59:59.999 202 | */ 203 | 204 | function endOfMonth(dirtyDate) { 205 | requiredArgs(1, arguments); 206 | var date = toDate(dirtyDate); 207 | var month = date.getMonth(); 208 | date.setFullYear(date.getFullYear(), month + 1, 0); 209 | date.setHours(23, 59, 59, 999); 210 | return date; 211 | } 212 | 213 | /** 214 | * @name isLastDayOfMonth 215 | * @category Month Helpers 216 | * @summary Is the given date the last day of a month? 217 | * 218 | * @description 219 | * Is the given date the last day of a month? 220 | * 221 | * ### v2.0.0 breaking changes: 222 | * 223 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 224 | * 225 | * @param {Date|Number} date - the date to check 226 | * @returns {Boolean} the date is the last day of a month 227 | * @throws {TypeError} 1 argument required 228 | * 229 | * @example 230 | * // Is 28 February 2014 the last day of a month? 231 | * var result = isLastDayOfMonth(new Date(2014, 1, 28)) 232 | * //=> true 233 | */ 234 | 235 | function isLastDayOfMonth(dirtyDate) { 236 | requiredArgs(1, arguments); 237 | var date = toDate(dirtyDate); 238 | return endOfDay(date).getTime() === endOfMonth(date).getTime(); 239 | } 240 | 241 | /** 242 | * @name differenceInMonths 243 | * @category Month Helpers 244 | * @summary Get the number of full months between the given dates. 245 | * 246 | * @description 247 | * Get the number of full months between the given dates using trunc as a default rounding method. 248 | * 249 | * ### v2.0.0 breaking changes: 250 | * 251 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 252 | * 253 | * @param {Date|Number} dateLeft - the later date 254 | * @param {Date|Number} dateRight - the earlier date 255 | * @returns {Number} the number of full months 256 | * @throws {TypeError} 2 arguments required 257 | * 258 | * @example 259 | * // How many full months are between 31 January 2014 and 1 September 2014? 260 | * const result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31)) 261 | * //=> 7 262 | */ 263 | 264 | function differenceInMonths(dirtyDateLeft, dirtyDateRight) { 265 | requiredArgs(2, arguments); 266 | var dateLeft = toDate(dirtyDateLeft); 267 | var dateRight = toDate(dirtyDateRight); 268 | var sign = compareAsc(dateLeft, dateRight); 269 | var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight)); 270 | var result; // Check for the difference of less than month 271 | 272 | if (difference < 1) { 273 | result = 0; 274 | } else { 275 | if (dateLeft.getMonth() === 1 && dateLeft.getDate() > 27) { 276 | // This will check if the date is end of Feb and assign a higher end of month date 277 | // to compare it with Jan 278 | dateLeft.setDate(30); 279 | } 280 | 281 | dateLeft.setMonth(dateLeft.getMonth() - sign * difference); // Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full 282 | // If so, result must be decreased by 1 in absolute value 283 | 284 | var isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign; // Check for cases of one full calendar month 285 | 286 | if (isLastDayOfMonth(toDate(dirtyDateLeft)) && difference === 1 && compareAsc(dirtyDateLeft, dateRight) === 1) { 287 | isLastMonthNotFull = false; 288 | } 289 | 290 | result = sign * (difference - Number(isLastMonthNotFull)); 291 | } // Prevent negative zero 292 | 293 | 294 | return result === 0 ? 0 : result; 295 | } 296 | 297 | /** 298 | * @name differenceInMilliseconds 299 | * @category Millisecond Helpers 300 | * @summary Get the number of milliseconds between the given dates. 301 | * 302 | * @description 303 | * Get the number of milliseconds between the given dates. 304 | * 305 | * ### v2.0.0 breaking changes: 306 | * 307 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 308 | * 309 | * @param {Date|Number} dateLeft - the later date 310 | * @param {Date|Number} dateRight - the earlier date 311 | * @returns {Number} the number of milliseconds 312 | * @throws {TypeError} 2 arguments required 313 | * 314 | * @example 315 | * // How many milliseconds are between 316 | * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700? 317 | * const result = differenceInMilliseconds( 318 | * new Date(2014, 6, 2, 12, 30, 21, 700), 319 | * new Date(2014, 6, 2, 12, 30, 20, 600) 320 | * ) 321 | * //=> 1100 322 | */ 323 | 324 | function differenceInMilliseconds(dateLeft, dateRight) { 325 | requiredArgs(2, arguments); 326 | return toDate(dateLeft).getTime() - toDate(dateRight).getTime(); 327 | } 328 | 329 | var roundingMap = { 330 | ceil: Math.ceil, 331 | round: Math.round, 332 | floor: Math.floor, 333 | trunc: function (value) { 334 | return value < 0 ? Math.ceil(value) : Math.floor(value); 335 | } // Math.trunc is not supported by IE 336 | 337 | }; 338 | var defaultRoundingMethod = 'trunc'; 339 | function getRoundingMethod(method) { 340 | return method ? roundingMap[method] : roundingMap[defaultRoundingMethod]; 341 | } 342 | 343 | /** 344 | * @name differenceInSeconds 345 | * @category Second Helpers 346 | * @summary Get the number of seconds between the given dates. 347 | * 348 | * @description 349 | * Get the number of seconds between the given dates. 350 | * 351 | * ### v2.0.0 breaking changes: 352 | * 353 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 354 | * 355 | * @param {Date|Number} dateLeft - the later date 356 | * @param {Date|Number} dateRight - the earlier date 357 | * @param {Object} [options] - an object with options. 358 | * @param {String} [options.roundingMethod='trunc'] - a rounding method (`ceil`, `floor`, `round` or `trunc`) 359 | * @returns {Number} the number of seconds 360 | * @throws {TypeError} 2 arguments required 361 | * 362 | * @example 363 | * // How many seconds are between 364 | * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000? 365 | * const result = differenceInSeconds( 366 | * new Date(2014, 6, 2, 12, 30, 20, 0), 367 | * new Date(2014, 6, 2, 12, 30, 7, 999) 368 | * ) 369 | * //=> 12 370 | */ 371 | 372 | function differenceInSeconds(dateLeft, dateRight, options) { 373 | requiredArgs(2, arguments); 374 | var diff = differenceInMilliseconds(dateLeft, dateRight) / 1000; 375 | return getRoundingMethod(options === null || options === void 0 ? void 0 : options.roundingMethod)(diff); 376 | } 377 | 378 | var formatDistanceLocale = { 379 | lessThanXSeconds: { 380 | one: 'less than a second', 381 | other: 'less than {{count}} seconds' 382 | }, 383 | xSeconds: { 384 | one: '1 second', 385 | other: '{{count}} seconds' 386 | }, 387 | halfAMinute: 'half a minute', 388 | lessThanXMinutes: { 389 | one: 'less than a minute', 390 | other: 'less than {{count}} minutes' 391 | }, 392 | xMinutes: { 393 | one: '1 minute', 394 | other: '{{count}} minutes' 395 | }, 396 | aboutXHours: { 397 | one: 'about 1 hour', 398 | other: 'about {{count}} hours' 399 | }, 400 | xHours: { 401 | one: '1 hour', 402 | other: '{{count}} hours' 403 | }, 404 | xDays: { 405 | one: '1 day', 406 | other: '{{count}} days' 407 | }, 408 | aboutXWeeks: { 409 | one: 'about 1 week', 410 | other: 'about {{count}} weeks' 411 | }, 412 | xWeeks: { 413 | one: '1 week', 414 | other: '{{count}} weeks' 415 | }, 416 | aboutXMonths: { 417 | one: 'about 1 month', 418 | other: 'about {{count}} months' 419 | }, 420 | xMonths: { 421 | one: '1 month', 422 | other: '{{count}} months' 423 | }, 424 | aboutXYears: { 425 | one: 'about 1 year', 426 | other: 'about {{count}} years' 427 | }, 428 | xYears: { 429 | one: '1 year', 430 | other: '{{count}} years' 431 | }, 432 | overXYears: { 433 | one: 'over 1 year', 434 | other: 'over {{count}} years' 435 | }, 436 | almostXYears: { 437 | one: 'almost 1 year', 438 | other: 'almost {{count}} years' 439 | } 440 | }; 441 | 442 | var formatDistance$1 = function (token, count, options) { 443 | var result; 444 | var tokenValue = formatDistanceLocale[token]; 445 | 446 | if (typeof tokenValue === 'string') { 447 | result = tokenValue; 448 | } else if (count === 1) { 449 | result = tokenValue.one; 450 | } else { 451 | result = tokenValue.other.replace('{{count}}', count.toString()); 452 | } 453 | 454 | if (options !== null && options !== void 0 && options.addSuffix) { 455 | if (options.comparison && options.comparison > 0) { 456 | return 'in ' + result; 457 | } else { 458 | return result + ' ago'; 459 | } 460 | } 461 | 462 | return result; 463 | }; 464 | 465 | var formatDistance$2 = formatDistance$1; 466 | 467 | function buildFormatLongFn(args) { 468 | return function () { 469 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 470 | // TODO: Remove String() 471 | var width = options.width ? String(options.width) : args.defaultWidth; 472 | var format = args.formats[width] || args.formats[args.defaultWidth]; 473 | return format; 474 | }; 475 | } 476 | 477 | var dateFormats = { 478 | full: 'EEEE, MMMM do, y', 479 | long: 'MMMM do, y', 480 | medium: 'MMM d, y', 481 | short: 'MM/dd/yyyy' 482 | }; 483 | var timeFormats = { 484 | full: 'h:mm:ss a zzzz', 485 | long: 'h:mm:ss a z', 486 | medium: 'h:mm:ss a', 487 | short: 'h:mm a' 488 | }; 489 | var dateTimeFormats = { 490 | full: "{{date}} 'at' {{time}}", 491 | long: "{{date}} 'at' {{time}}", 492 | medium: '{{date}}, {{time}}', 493 | short: '{{date}}, {{time}}' 494 | }; 495 | var formatLong = { 496 | date: buildFormatLongFn({ 497 | formats: dateFormats, 498 | defaultWidth: 'full' 499 | }), 500 | time: buildFormatLongFn({ 501 | formats: timeFormats, 502 | defaultWidth: 'full' 503 | }), 504 | dateTime: buildFormatLongFn({ 505 | formats: dateTimeFormats, 506 | defaultWidth: 'full' 507 | }) 508 | }; 509 | var formatLong$1 = formatLong; 510 | 511 | var formatRelativeLocale = { 512 | lastWeek: "'last' eeee 'at' p", 513 | yesterday: "'yesterday at' p", 514 | today: "'today at' p", 515 | tomorrow: "'tomorrow at' p", 516 | nextWeek: "eeee 'at' p", 517 | other: 'P' 518 | }; 519 | 520 | var formatRelative = function (token, _date, _baseDate, _options) { 521 | return formatRelativeLocale[token]; 522 | }; 523 | 524 | var formatRelative$1 = formatRelative; 525 | 526 | function buildLocalizeFn(args) { 527 | return function (dirtyIndex, dirtyOptions) { 528 | var options = dirtyOptions || {}; 529 | var context = options.context ? String(options.context) : 'standalone'; 530 | var valuesArray; 531 | 532 | if (context === 'formatting' && args.formattingValues) { 533 | var defaultWidth = args.defaultFormattingWidth || args.defaultWidth; 534 | var width = options.width ? String(options.width) : defaultWidth; 535 | valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth]; 536 | } else { 537 | var _defaultWidth = args.defaultWidth; 538 | 539 | var _width = options.width ? String(options.width) : args.defaultWidth; 540 | 541 | valuesArray = args.values[_width] || args.values[_defaultWidth]; 542 | } 543 | 544 | var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; // @ts-ignore: For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it! 545 | 546 | return valuesArray[index]; 547 | }; 548 | } 549 | 550 | var eraValues = { 551 | narrow: ['B', 'A'], 552 | abbreviated: ['BC', 'AD'], 553 | wide: ['Before Christ', 'Anno Domini'] 554 | }; 555 | var quarterValues = { 556 | narrow: ['1', '2', '3', '4'], 557 | abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'], 558 | wide: ['1st quarter', '2nd quarter', '3rd quarter', '4th quarter'] 559 | }; // Note: in English, the names of days of the week and months are capitalized. 560 | // If you are making a new locale based on this one, check if the same is true for the language you're working on. 561 | // Generally, formatted dates should look like they are in the middle of a sentence, 562 | // e.g. in Spanish language the weekdays and months should be in the lowercase. 563 | 564 | var monthValues = { 565 | narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'], 566 | abbreviated: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], 567 | wide: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] 568 | }; 569 | var dayValues = { 570 | narrow: ['S', 'M', 'T', 'W', 'T', 'F', 'S'], 571 | short: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], 572 | abbreviated: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], 573 | wide: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] 574 | }; 575 | var dayPeriodValues = { 576 | narrow: { 577 | am: 'a', 578 | pm: 'p', 579 | midnight: 'mi', 580 | noon: 'n', 581 | morning: 'morning', 582 | afternoon: 'afternoon', 583 | evening: 'evening', 584 | night: 'night' 585 | }, 586 | abbreviated: { 587 | am: 'AM', 588 | pm: 'PM', 589 | midnight: 'midnight', 590 | noon: 'noon', 591 | morning: 'morning', 592 | afternoon: 'afternoon', 593 | evening: 'evening', 594 | night: 'night' 595 | }, 596 | wide: { 597 | am: 'a.m.', 598 | pm: 'p.m.', 599 | midnight: 'midnight', 600 | noon: 'noon', 601 | morning: 'morning', 602 | afternoon: 'afternoon', 603 | evening: 'evening', 604 | night: 'night' 605 | } 606 | }; 607 | var formattingDayPeriodValues = { 608 | narrow: { 609 | am: 'a', 610 | pm: 'p', 611 | midnight: 'mi', 612 | noon: 'n', 613 | morning: 'in the morning', 614 | afternoon: 'in the afternoon', 615 | evening: 'in the evening', 616 | night: 'at night' 617 | }, 618 | abbreviated: { 619 | am: 'AM', 620 | pm: 'PM', 621 | midnight: 'midnight', 622 | noon: 'noon', 623 | morning: 'in the morning', 624 | afternoon: 'in the afternoon', 625 | evening: 'in the evening', 626 | night: 'at night' 627 | }, 628 | wide: { 629 | am: 'a.m.', 630 | pm: 'p.m.', 631 | midnight: 'midnight', 632 | noon: 'noon', 633 | morning: 'in the morning', 634 | afternoon: 'in the afternoon', 635 | evening: 'in the evening', 636 | night: 'at night' 637 | } 638 | }; 639 | 640 | var ordinalNumber = function (dirtyNumber, _options) { 641 | var number = Number(dirtyNumber); // If ordinal numbers depend on context, for example, 642 | // if they are different for different grammatical genders, 643 | // use `options.unit`. 644 | // 645 | // `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear', 646 | // 'day', 'hour', 'minute', 'second'. 647 | 648 | var rem100 = number % 100; 649 | 650 | if (rem100 > 20 || rem100 < 10) { 651 | switch (rem100 % 10) { 652 | case 1: 653 | return number + 'st'; 654 | 655 | case 2: 656 | return number + 'nd'; 657 | 658 | case 3: 659 | return number + 'rd'; 660 | } 661 | } 662 | 663 | return number + 'th'; 664 | }; 665 | 666 | var localize = { 667 | ordinalNumber: ordinalNumber, 668 | era: buildLocalizeFn({ 669 | values: eraValues, 670 | defaultWidth: 'wide' 671 | }), 672 | quarter: buildLocalizeFn({ 673 | values: quarterValues, 674 | defaultWidth: 'wide', 675 | argumentCallback: function (quarter) { 676 | return quarter - 1; 677 | } 678 | }), 679 | month: buildLocalizeFn({ 680 | values: monthValues, 681 | defaultWidth: 'wide' 682 | }), 683 | day: buildLocalizeFn({ 684 | values: dayValues, 685 | defaultWidth: 'wide' 686 | }), 687 | dayPeriod: buildLocalizeFn({ 688 | values: dayPeriodValues, 689 | defaultWidth: 'wide', 690 | formattingValues: formattingDayPeriodValues, 691 | defaultFormattingWidth: 'wide' 692 | }) 693 | }; 694 | var localize$1 = localize; 695 | 696 | function buildMatchFn(args) { 697 | return function (string) { 698 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 699 | var width = options.width; 700 | var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth]; 701 | var matchResult = string.match(matchPattern); 702 | 703 | if (!matchResult) { 704 | return null; 705 | } 706 | 707 | var matchedString = matchResult[0]; 708 | var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth]; 709 | var key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, function (pattern) { 710 | return pattern.test(matchedString); 711 | }) : findKey(parsePatterns, function (pattern) { 712 | return pattern.test(matchedString); 713 | }); 714 | var value; 715 | value = args.valueCallback ? args.valueCallback(key) : key; 716 | value = options.valueCallback ? options.valueCallback(value) : value; 717 | var rest = string.slice(matchedString.length); 718 | return { 719 | value: value, 720 | rest: rest 721 | }; 722 | }; 723 | } 724 | 725 | function findKey(object, predicate) { 726 | for (var key in object) { 727 | if (object.hasOwnProperty(key) && predicate(object[key])) { 728 | return key; 729 | } 730 | } 731 | 732 | return undefined; 733 | } 734 | 735 | function findIndex(array, predicate) { 736 | for (var key = 0; key < array.length; key++) { 737 | if (predicate(array[key])) { 738 | return key; 739 | } 740 | } 741 | 742 | return undefined; 743 | } 744 | 745 | function buildMatchPatternFn(args) { 746 | return function (string) { 747 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 748 | var matchResult = string.match(args.matchPattern); 749 | if (!matchResult) return null; 750 | var matchedString = matchResult[0]; 751 | var parseResult = string.match(args.parsePattern); 752 | if (!parseResult) return null; 753 | var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0]; 754 | value = options.valueCallback ? options.valueCallback(value) : value; 755 | var rest = string.slice(matchedString.length); 756 | return { 757 | value: value, 758 | rest: rest 759 | }; 760 | }; 761 | } 762 | 763 | var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i; 764 | var parseOrdinalNumberPattern = /\d+/i; 765 | var matchEraPatterns = { 766 | narrow: /^(b|a)/i, 767 | abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i, 768 | wide: /^(before christ|before common era|anno domini|common era)/i 769 | }; 770 | var parseEraPatterns = { 771 | any: [/^b/i, /^(a|c)/i] 772 | }; 773 | var matchQuarterPatterns = { 774 | narrow: /^[1234]/i, 775 | abbreviated: /^q[1234]/i, 776 | wide: /^[1234](th|st|nd|rd)? quarter/i 777 | }; 778 | var parseQuarterPatterns = { 779 | any: [/1/i, /2/i, /3/i, /4/i] 780 | }; 781 | var matchMonthPatterns = { 782 | narrow: /^[jfmasond]/i, 783 | abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i, 784 | wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i 785 | }; 786 | var parseMonthPatterns = { 787 | narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i], 788 | any: [/^ja/i, /^f/i, /^mar/i, /^ap/i, /^may/i, /^jun/i, /^jul/i, /^au/i, /^s/i, /^o/i, /^n/i, /^d/i] 789 | }; 790 | var matchDayPatterns = { 791 | narrow: /^[smtwf]/i, 792 | short: /^(su|mo|tu|we|th|fr|sa)/i, 793 | abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i, 794 | wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i 795 | }; 796 | var parseDayPatterns = { 797 | narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i], 798 | any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i] 799 | }; 800 | var matchDayPeriodPatterns = { 801 | narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i, 802 | any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i 803 | }; 804 | var parseDayPeriodPatterns = { 805 | any: { 806 | am: /^a/i, 807 | pm: /^p/i, 808 | midnight: /^mi/i, 809 | noon: /^no/i, 810 | morning: /morning/i, 811 | afternoon: /afternoon/i, 812 | evening: /evening/i, 813 | night: /night/i 814 | } 815 | }; 816 | var match = { 817 | ordinalNumber: buildMatchPatternFn({ 818 | matchPattern: matchOrdinalNumberPattern, 819 | parsePattern: parseOrdinalNumberPattern, 820 | valueCallback: function (value) { 821 | return parseInt(value, 10); 822 | } 823 | }), 824 | era: buildMatchFn({ 825 | matchPatterns: matchEraPatterns, 826 | defaultMatchWidth: 'wide', 827 | parsePatterns: parseEraPatterns, 828 | defaultParseWidth: 'any' 829 | }), 830 | quarter: buildMatchFn({ 831 | matchPatterns: matchQuarterPatterns, 832 | defaultMatchWidth: 'wide', 833 | parsePatterns: parseQuarterPatterns, 834 | defaultParseWidth: 'any', 835 | valueCallback: function (index) { 836 | return index + 1; 837 | } 838 | }), 839 | month: buildMatchFn({ 840 | matchPatterns: matchMonthPatterns, 841 | defaultMatchWidth: 'wide', 842 | parsePatterns: parseMonthPatterns, 843 | defaultParseWidth: 'any' 844 | }), 845 | day: buildMatchFn({ 846 | matchPatterns: matchDayPatterns, 847 | defaultMatchWidth: 'wide', 848 | parsePatterns: parseDayPatterns, 849 | defaultParseWidth: 'any' 850 | }), 851 | dayPeriod: buildMatchFn({ 852 | matchPatterns: matchDayPeriodPatterns, 853 | defaultMatchWidth: 'any', 854 | parsePatterns: parseDayPeriodPatterns, 855 | defaultParseWidth: 'any' 856 | }) 857 | }; 858 | var match$1 = match; 859 | 860 | /** 861 | * @type {Locale} 862 | * @category Locales 863 | * @summary English locale (United States). 864 | * @language English 865 | * @iso-639-2 eng 866 | * @author Sasha Koss [@kossnocorp]{@link https://github.com/kossnocorp} 867 | * @author Lesha Koss [@leshakoss]{@link https://github.com/leshakoss} 868 | */ 869 | var locale$1 = { 870 | code: 'en-US', 871 | formatDistance: formatDistance$2, 872 | formatLong: formatLong$1, 873 | formatRelative: formatRelative$1, 874 | localize: localize$1, 875 | match: match$1, 876 | options: { 877 | weekStartsOn: 0 878 | /* Sunday */ 879 | , 880 | firstWeekContainsDate: 1 881 | } 882 | }; 883 | var defaultLocale = locale$1; 884 | 885 | function assign(target, dirtyObject) { 886 | if (target == null) { 887 | throw new TypeError('assign requires that input parameter not be null or undefined'); 888 | } 889 | 890 | dirtyObject = dirtyObject || {}; 891 | 892 | for (var property in dirtyObject) { 893 | if (Object.prototype.hasOwnProperty.call(dirtyObject, property)) { 894 | target[property] = dirtyObject[property]; 895 | } 896 | } 897 | 898 | return target; 899 | } 900 | 901 | function cloneObject(dirtyObject) { 902 | return assign({}, dirtyObject); 903 | } 904 | 905 | /** 906 | * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds. 907 | * They usually appear for dates that denote time before the timezones were introduced 908 | * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891 909 | * and GMT+01:00:00 after that date) 910 | * 911 | * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above, 912 | * which would lead to incorrect calculations. 913 | * 914 | * This function returns the timezone offset in milliseconds that takes seconds in account. 915 | */ 916 | function getTimezoneOffsetInMilliseconds(date) { 917 | var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds())); 918 | utcDate.setUTCFullYear(date.getFullYear()); 919 | return date.getTime() - utcDate.getTime(); 920 | } 921 | 922 | var MINUTES_IN_DAY$1 = 1440; 923 | var MINUTES_IN_ALMOST_TWO_DAYS = 2520; 924 | var MINUTES_IN_MONTH$1 = 43200; 925 | var MINUTES_IN_TWO_MONTHS = 86400; 926 | /** 927 | * @name formatDistance 928 | * @category Common Helpers 929 | * @summary Return the distance between the given dates in words. 930 | * 931 | * @description 932 | * Return the distance between the given dates in words. 933 | * 934 | * | Distance between dates | Result | 935 | * |-------------------------------------------------------------------|---------------------| 936 | * | 0 ... 30 secs | less than a minute | 937 | * | 30 secs ... 1 min 30 secs | 1 minute | 938 | * | 1 min 30 secs ... 44 mins 30 secs | [2..44] minutes | 939 | * | 44 mins ... 30 secs ... 89 mins 30 secs | about 1 hour | 940 | * | 89 mins 30 secs ... 23 hrs 59 mins 30 secs | about [2..24] hours | 941 | * | 23 hrs 59 mins 30 secs ... 41 hrs 59 mins 30 secs | 1 day | 942 | * | 41 hrs 59 mins 30 secs ... 29 days 23 hrs 59 mins 30 secs | [2..30] days | 943 | * | 29 days 23 hrs 59 mins 30 secs ... 44 days 23 hrs 59 mins 30 secs | about 1 month | 944 | * | 44 days 23 hrs 59 mins 30 secs ... 59 days 23 hrs 59 mins 30 secs | about 2 months | 945 | * | 59 days 23 hrs 59 mins 30 secs ... 1 yr | [2..12] months | 946 | * | 1 yr ... 1 yr 3 months | about 1 year | 947 | * | 1 yr 3 months ... 1 yr 9 month s | over 1 year | 948 | * | 1 yr 9 months ... 2 yrs | almost 2 years | 949 | * | N yrs ... N yrs 3 months | about N years | 950 | * | N yrs 3 months ... N yrs 9 months | over N years | 951 | * | N yrs 9 months ... N+1 yrs | almost N+1 years | 952 | * 953 | * With `options.includeSeconds == true`: 954 | * | Distance between dates | Result | 955 | * |------------------------|----------------------| 956 | * | 0 secs ... 5 secs | less than 5 seconds | 957 | * | 5 secs ... 10 secs | less than 10 seconds | 958 | * | 10 secs ... 20 secs | less than 20 seconds | 959 | * | 20 secs ... 40 secs | half a minute | 960 | * | 40 secs ... 60 secs | less than a minute | 961 | * | 60 secs ... 90 secs | 1 minute | 962 | * 963 | * ### v2.0.0 breaking changes: 964 | * 965 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 966 | * 967 | * - The function was renamed from `distanceInWords ` to `formatDistance` 968 | * to make its name consistent with `format` and `formatRelative`. 969 | * 970 | * - The order of arguments is swapped to make the function 971 | * consistent with `differenceIn...` functions. 972 | * 973 | * ```javascript 974 | * // Before v2.0.0 975 | * 976 | * distanceInWords( 977 | * new Date(1986, 3, 4, 10, 32, 0), 978 | * new Date(1986, 3, 4, 11, 32, 0), 979 | * { addSuffix: true } 980 | * ) //=> 'in about 1 hour' 981 | * 982 | * // v2.0.0 onward 983 | * 984 | * formatDistance( 985 | * new Date(1986, 3, 4, 11, 32, 0), 986 | * new Date(1986, 3, 4, 10, 32, 0), 987 | * { addSuffix: true } 988 | * ) //=> 'in about 1 hour' 989 | * ``` 990 | * 991 | * @param {Date|Number} date - the date 992 | * @param {Date|Number} baseDate - the date to compare with 993 | * @param {Object} [options] - an object with options. 994 | * @param {Boolean} [options.includeSeconds=false] - distances less than a minute are more detailed 995 | * @param {Boolean} [options.addSuffix=false] - result indicates if the second date is earlier or later than the first 996 | * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale} 997 | * @returns {String} the distance in words 998 | * @throws {TypeError} 2 arguments required 999 | * @throws {RangeError} `date` must not be Invalid Date 1000 | * @throws {RangeError} `baseDate` must not be Invalid Date 1001 | * @throws {RangeError} `options.locale` must contain `formatDistance` property 1002 | * 1003 | * @example 1004 | * // What is the distance between 2 July 2014 and 1 January 2015? 1005 | * const result = formatDistance(new Date(2014, 6, 2), new Date(2015, 0, 1)) 1006 | * //=> '6 months' 1007 | * 1008 | * @example 1009 | * // What is the distance between 1 January 2015 00:00:15 1010 | * // and 1 January 2015 00:00:00, including seconds? 1011 | * const result = formatDistance( 1012 | * new Date(2015, 0, 1, 0, 0, 15), 1013 | * new Date(2015, 0, 1, 0, 0, 0), 1014 | * { includeSeconds: true } 1015 | * ) 1016 | * //=> 'less than 20 seconds' 1017 | * 1018 | * @example 1019 | * // What is the distance from 1 January 2016 1020 | * // to 1 January 2015, with a suffix? 1021 | * const result = formatDistance(new Date(2015, 0, 1), new Date(2016, 0, 1), { 1022 | * addSuffix: true 1023 | * }) 1024 | * //=> 'about 1 year ago' 1025 | * 1026 | * @example 1027 | * // What is the distance between 1 August 2016 and 1 January 2015 in Esperanto? 1028 | * import { eoLocale } from 'date-fns/locale/eo' 1029 | * const result = formatDistance(new Date(2016, 7, 1), new Date(2015, 0, 1), { 1030 | * locale: eoLocale 1031 | * }) 1032 | * //=> 'pli ol 1 jaro' 1033 | */ 1034 | 1035 | function formatDistance(dirtyDate, dirtyBaseDate) { 1036 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; 1037 | requiredArgs(2, arguments); 1038 | var locale = options.locale || defaultLocale; 1039 | 1040 | if (!locale.formatDistance) { 1041 | throw new RangeError('locale must contain formatDistance property'); 1042 | } 1043 | 1044 | var comparison = compareAsc(dirtyDate, dirtyBaseDate); 1045 | 1046 | if (isNaN(comparison)) { 1047 | throw new RangeError('Invalid time value'); 1048 | } 1049 | 1050 | var localizeOptions = cloneObject(options); 1051 | localizeOptions.addSuffix = Boolean(options.addSuffix); 1052 | localizeOptions.comparison = comparison; 1053 | var dateLeft; 1054 | var dateRight; 1055 | 1056 | if (comparison > 0) { 1057 | dateLeft = toDate(dirtyBaseDate); 1058 | dateRight = toDate(dirtyDate); 1059 | } else { 1060 | dateLeft = toDate(dirtyDate); 1061 | dateRight = toDate(dirtyBaseDate); 1062 | } 1063 | 1064 | var seconds = differenceInSeconds(dateRight, dateLeft); 1065 | var offsetInSeconds = (getTimezoneOffsetInMilliseconds(dateRight) - getTimezoneOffsetInMilliseconds(dateLeft)) / 1000; 1066 | var minutes = Math.round((seconds - offsetInSeconds) / 60); 1067 | var months; // 0 up to 2 mins 1068 | 1069 | if (minutes < 2) { 1070 | if (options.includeSeconds) { 1071 | if (seconds < 5) { 1072 | return locale.formatDistance('lessThanXSeconds', 5, localizeOptions); 1073 | } else if (seconds < 10) { 1074 | return locale.formatDistance('lessThanXSeconds', 10, localizeOptions); 1075 | } else if (seconds < 20) { 1076 | return locale.formatDistance('lessThanXSeconds', 20, localizeOptions); 1077 | } else if (seconds < 40) { 1078 | return locale.formatDistance('halfAMinute', null, localizeOptions); 1079 | } else if (seconds < 60) { 1080 | return locale.formatDistance('lessThanXMinutes', 1, localizeOptions); 1081 | } else { 1082 | return locale.formatDistance('xMinutes', 1, localizeOptions); 1083 | } 1084 | } else { 1085 | if (minutes === 0) { 1086 | return locale.formatDistance('lessThanXMinutes', 1, localizeOptions); 1087 | } else { 1088 | return locale.formatDistance('xMinutes', minutes, localizeOptions); 1089 | } 1090 | } // 2 mins up to 0.75 hrs 1091 | 1092 | } else if (minutes < 45) { 1093 | return locale.formatDistance('xMinutes', minutes, localizeOptions); // 0.75 hrs up to 1.5 hrs 1094 | } else if (minutes < 90) { 1095 | return locale.formatDistance('aboutXHours', 1, localizeOptions); // 1.5 hrs up to 24 hrs 1096 | } else if (minutes < MINUTES_IN_DAY$1) { 1097 | var hours = Math.round(minutes / 60); 1098 | return locale.formatDistance('aboutXHours', hours, localizeOptions); // 1 day up to 1.75 days 1099 | } else if (minutes < MINUTES_IN_ALMOST_TWO_DAYS) { 1100 | return locale.formatDistance('xDays', 1, localizeOptions); // 1.75 days up to 30 days 1101 | } else if (minutes < MINUTES_IN_MONTH$1) { 1102 | var days = Math.round(minutes / MINUTES_IN_DAY$1); 1103 | return locale.formatDistance('xDays', days, localizeOptions); // 1 month up to 2 months 1104 | } else if (minutes < MINUTES_IN_TWO_MONTHS) { 1105 | months = Math.round(minutes / MINUTES_IN_MONTH$1); 1106 | return locale.formatDistance('aboutXMonths', months, localizeOptions); 1107 | } 1108 | 1109 | months = differenceInMonths(dateRight, dateLeft); // 2 months up to 12 months 1110 | 1111 | if (months < 12) { 1112 | var nearestMonth = Math.round(minutes / MINUTES_IN_MONTH$1); 1113 | return locale.formatDistance('xMonths', nearestMonth, localizeOptions); // 1 year up to max Date 1114 | } else { 1115 | var monthsSinceStartOfYear = months % 12; 1116 | var years = Math.floor(months / 12); // N years up to 1 years 3 months 1117 | 1118 | if (monthsSinceStartOfYear < 3) { 1119 | return locale.formatDistance('aboutXYears', years, localizeOptions); // N years 3 months up to N years 9 months 1120 | } else if (monthsSinceStartOfYear < 9) { 1121 | return locale.formatDistance('overXYears', years, localizeOptions); // N years 9 months up to N year 12 months 1122 | } else { 1123 | return locale.formatDistance('almostXYears', years + 1, localizeOptions); 1124 | } 1125 | } 1126 | } 1127 | 1128 | /** 1129 | * @name formatDistanceToNow 1130 | * @category Common Helpers 1131 | * @summary Return the distance between the given date and now in words. 1132 | * @pure false 1133 | * 1134 | * @description 1135 | * Return the distance between the given date and now in words. 1136 | * 1137 | * | Distance to now | Result | 1138 | * |-------------------------------------------------------------------|---------------------| 1139 | * | 0 ... 30 secs | less than a minute | 1140 | * | 30 secs ... 1 min 30 secs | 1 minute | 1141 | * | 1 min 30 secs ... 44 mins 30 secs | [2..44] minutes | 1142 | * | 44 mins ... 30 secs ... 89 mins 30 secs | about 1 hour | 1143 | * | 89 mins 30 secs ... 23 hrs 59 mins 30 secs | about [2..24] hours | 1144 | * | 23 hrs 59 mins 30 secs ... 41 hrs 59 mins 30 secs | 1 day | 1145 | * | 41 hrs 59 mins 30 secs ... 29 days 23 hrs 59 mins 30 secs | [2..30] days | 1146 | * | 29 days 23 hrs 59 mins 30 secs ... 44 days 23 hrs 59 mins 30 secs | about 1 month | 1147 | * | 44 days 23 hrs 59 mins 30 secs ... 59 days 23 hrs 59 mins 30 secs | about 2 months | 1148 | * | 59 days 23 hrs 59 mins 30 secs ... 1 yr | [2..12] months | 1149 | * | 1 yr ... 1 yr 3 months | about 1 year | 1150 | * | 1 yr 3 months ... 1 yr 9 month s | over 1 year | 1151 | * | 1 yr 9 months ... 2 yrs | almost 2 years | 1152 | * | N yrs ... N yrs 3 months | about N years | 1153 | * | N yrs 3 months ... N yrs 9 months | over N years | 1154 | * | N yrs 9 months ... N+1 yrs | almost N+1 years | 1155 | * 1156 | * With `options.includeSeconds == true`: 1157 | * | Distance to now | Result | 1158 | * |---------------------|----------------------| 1159 | * | 0 secs ... 5 secs | less than 5 seconds | 1160 | * | 5 secs ... 10 secs | less than 10 seconds | 1161 | * | 10 secs ... 20 secs | less than 20 seconds | 1162 | * | 20 secs ... 40 secs | half a minute | 1163 | * | 40 secs ... 60 secs | less than a minute | 1164 | * | 60 secs ... 90 secs | 1 minute | 1165 | * 1166 | * > ⚠️ Please note that this function is not present in the FP submodule as 1167 | * > it uses `Date.now()` internally hence impure and can't be safely curried. 1168 | * 1169 | * ### v2.0.0 breaking changes: 1170 | * 1171 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1172 | * 1173 | * - The function was renamed from `distanceInWordsToNow ` to `formatDistanceToNow` 1174 | * to make its name consistent with `format` and `formatRelative`. 1175 | * 1176 | * ```javascript 1177 | * // Before v2.0.0 1178 | * 1179 | * distanceInWordsToNow(new Date(2014, 6, 2), { addSuffix: true }) 1180 | * //=> 'in 6 months' 1181 | * 1182 | * // v2.0.0 onward 1183 | * 1184 | * formatDistanceToNow(new Date(2014, 6, 2), { addSuffix: true }) 1185 | * //=> 'in 6 months' 1186 | * ``` 1187 | * 1188 | * @param {Date|Number} date - the given date 1189 | * @param {Object} [options] - the object with options 1190 | * @param {Boolean} [options.includeSeconds=false] - distances less than a minute are more detailed 1191 | * @param {Boolean} [options.addSuffix=false] - result specifies if now is earlier or later than the passed date 1192 | * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale} 1193 | * @returns {String} the distance in words 1194 | * @throws {TypeError} 1 argument required 1195 | * @throws {RangeError} `date` must not be Invalid Date 1196 | * @throws {RangeError} `options.locale` must contain `formatDistance` property 1197 | * 1198 | * @example 1199 | * // If today is 1 January 2015, what is the distance to 2 July 2014? 1200 | * var result = formatDistanceToNow( 1201 | * new Date(2014, 6, 2) 1202 | * ) 1203 | * //=> '6 months' 1204 | * 1205 | * @example 1206 | * // If now is 1 January 2015 00:00:00, 1207 | * // what is the distance to 1 January 2015 00:00:15, including seconds? 1208 | * var result = formatDistanceToNow( 1209 | * new Date(2015, 0, 1, 0, 0, 15), 1210 | * {includeSeconds: true} 1211 | * ) 1212 | * //=> 'less than 20 seconds' 1213 | * 1214 | * @example 1215 | * // If today is 1 January 2015, 1216 | * // what is the distance to 1 January 2016, with a suffix? 1217 | * var result = formatDistanceToNow( 1218 | * new Date(2016, 0, 1), 1219 | * {addSuffix: true} 1220 | * ) 1221 | * //=> 'in about 1 year' 1222 | * 1223 | * @example 1224 | * // If today is 1 January 2015, 1225 | * // what is the distance to 1 August 2016 in Esperanto? 1226 | * var eoLocale = require('date-fns/locale/eo') 1227 | * var result = formatDistanceToNow( 1228 | * new Date(2016, 7, 1), 1229 | * {locale: eoLocale} 1230 | * ) 1231 | * //=> 'pli ol 1 jaro' 1232 | */ 1233 | 1234 | function formatDistanceToNow(dirtyDate, dirtyOptions) { 1235 | requiredArgs(1, arguments); 1236 | return formatDistance(dirtyDate, Date.now(), dirtyOptions); 1237 | } 1238 | 1239 | var MILLISECONDS_IN_MINUTE = 1000 * 60; 1240 | var MINUTES_IN_DAY = 60 * 24; 1241 | var MINUTES_IN_MONTH = MINUTES_IN_DAY * 30; 1242 | var MINUTES_IN_YEAR = MINUTES_IN_DAY * 365; 1243 | /** 1244 | * @name formatDistanceStrict 1245 | * @category Common Helpers 1246 | * @summary Return the distance between the given dates in words. 1247 | * 1248 | * @description 1249 | * Return the distance between the given dates in words, using strict units. 1250 | * This is like `formatDistance`, but does not use helpers like 'almost', 'over', 1251 | * 'less than' and the like. 1252 | * 1253 | * | Distance between dates | Result | 1254 | * |------------------------|---------------------| 1255 | * | 0 ... 59 secs | [0..59] seconds | 1256 | * | 1 ... 59 mins | [1..59] minutes | 1257 | * | 1 ... 23 hrs | [1..23] hours | 1258 | * | 1 ... 29 days | [1..29] days | 1259 | * | 1 ... 11 months | [1..11] months | 1260 | * | 1 ... N years | [1..N] years | 1261 | * 1262 | * ### v2.0.0 breaking changes: 1263 | * 1264 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1265 | * 1266 | * - The function was renamed from `distanceInWordsStrict` to `formatDistanceStrict` 1267 | * to make its name consistent with `format` and `formatRelative`. 1268 | * 1269 | * - The order of arguments is swapped to make the function 1270 | * consistent with `differenceIn...` functions. 1271 | * 1272 | * ```javascript 1273 | * // Before v2.0.0 1274 | * 1275 | * distanceInWordsStrict( 1276 | * new Date(2015, 0, 2), 1277 | * new Date(2014, 6, 2) 1278 | * ) //=> '6 months' 1279 | * 1280 | * // v2.0.0 onward 1281 | * 1282 | * formatDistanceStrict( 1283 | * new Date(2014, 6, 2), 1284 | * new Date(2015, 0, 2) 1285 | * ) //=> '6 months' 1286 | * ``` 1287 | * 1288 | * - `partialMethod` option is renamed to `roundingMethod`. 1289 | * 1290 | * ```javascript 1291 | * // Before v2.0.0 1292 | * 1293 | * distanceInWordsStrict( 1294 | * new Date(1986, 3, 4, 10, 32, 0), 1295 | * new Date(1986, 3, 4, 10, 33, 1), 1296 | * { partialMethod: 'ceil' } 1297 | * ) //=> '2 minutes' 1298 | * 1299 | * // v2.0.0 onward 1300 | * 1301 | * formatDistanceStrict( 1302 | * new Date(1986, 3, 4, 10, 33, 1), 1303 | * new Date(1986, 3, 4, 10, 32, 0), 1304 | * { roundingMethod: 'ceil' } 1305 | * ) //=> '2 minutes' 1306 | * ``` 1307 | * 1308 | * - If `roundingMethod` is not specified, it now defaults to `round` instead of `floor`. 1309 | * 1310 | * - `unit` option now accepts one of the strings: 1311 | * 'second', 'minute', 'hour', 'day', 'month' or 'year' instead of 's', 'm', 'h', 'd', 'M' or 'Y' 1312 | * 1313 | * ```javascript 1314 | * // Before v2.0.0 1315 | * 1316 | * distanceInWordsStrict( 1317 | * new Date(1986, 3, 4, 10, 32, 0), 1318 | * new Date(1986, 3, 4, 10, 33, 1), 1319 | * { unit: 'm' } 1320 | * ) 1321 | * 1322 | * // v2.0.0 onward 1323 | * 1324 | * formatDistanceStrict( 1325 | * new Date(1986, 3, 4, 10, 33, 1), 1326 | * new Date(1986, 3, 4, 10, 32, 0), 1327 | * { unit: 'minute' } 1328 | * ) 1329 | * ``` 1330 | * 1331 | * @param {Date|Number} date - the date 1332 | * @param {Date|Number} baseDate - the date to compare with 1333 | * @param {Object} [options] - an object with options. 1334 | * @param {Boolean} [options.addSuffix=false] - result indicates if the second date is earlier or later than the first 1335 | * @param {'second'|'minute'|'hour'|'day'|'month'|'year'} [options.unit] - if specified, will force a unit 1336 | * @param {'floor'|'ceil'|'round'} [options.roundingMethod='round'] - which way to round partial units 1337 | * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale} 1338 | * @returns {String} the distance in words 1339 | * @throws {TypeError} 2 arguments required 1340 | * @throws {RangeError} `date` must not be Invalid Date 1341 | * @throws {RangeError} `baseDate` must not be Invalid Date 1342 | * @throws {RangeError} `options.roundingMethod` must be 'floor', 'ceil' or 'round' 1343 | * @throws {RangeError} `options.unit` must be 'second', 'minute', 'hour', 'day', 'month' or 'year' 1344 | * @throws {RangeError} `options.locale` must contain `formatDistance` property 1345 | * 1346 | * @example 1347 | * // What is the distance between 2 July 2014 and 1 January 2015? 1348 | * const result = formatDistanceStrict(new Date(2014, 6, 2), new Date(2015, 0, 2)) 1349 | * //=> '6 months' 1350 | * 1351 | * @example 1352 | * // What is the distance between 1 January 2015 00:00:15 1353 | * // and 1 January 2015 00:00:00? 1354 | * const result = formatDistanceStrict( 1355 | * new Date(2015, 0, 1, 0, 0, 15), 1356 | * new Date(2015, 0, 1, 0, 0, 0) 1357 | * ) 1358 | * //=> '15 seconds' 1359 | * 1360 | * @example 1361 | * // What is the distance from 1 January 2016 1362 | * // to 1 January 2015, with a suffix? 1363 | * const result = formatDistanceStrict(new Date(2015, 0, 1), new Date(2016, 0, 1), { 1364 | * addSuffix: true 1365 | * }) 1366 | * //=> '1 year ago' 1367 | * 1368 | * @example 1369 | * // What is the distance from 1 January 2016 1370 | * // to 1 January 2015, in minutes? 1371 | * const result = formatDistanceStrict(new Date(2016, 0, 1), new Date(2015, 0, 1), { 1372 | * unit: 'minute' 1373 | * }) 1374 | * //=> '525600 minutes' 1375 | * 1376 | * @example 1377 | * // What is the distance from 1 January 2015 1378 | * // to 28 January 2015, in months, rounded up? 1379 | * const result = formatDistanceStrict(new Date(2015, 0, 28), new Date(2015, 0, 1), { 1380 | * unit: 'month', 1381 | * roundingMethod: 'ceil' 1382 | * }) 1383 | * //=> '1 month' 1384 | * 1385 | * @example 1386 | * // What is the distance between 1 August 2016 and 1 January 2015 in Esperanto? 1387 | * import { eoLocale } from 'date-fns/locale/eo' 1388 | * const result = formatDistanceStrict(new Date(2016, 7, 1), new Date(2015, 0, 1), { 1389 | * locale: eoLocale 1390 | * }) 1391 | * //=> '1 jaro' 1392 | */ 1393 | 1394 | function formatDistanceStrict(dirtyDate, dirtyBaseDate) { 1395 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; 1396 | requiredArgs(2, arguments); 1397 | var locale = options.locale || defaultLocale; 1398 | 1399 | if (!locale.formatDistance) { 1400 | throw new RangeError('locale must contain localize.formatDistance property'); 1401 | } 1402 | 1403 | var comparison = compareAsc(dirtyDate, dirtyBaseDate); 1404 | 1405 | if (isNaN(comparison)) { 1406 | throw new RangeError('Invalid time value'); 1407 | } 1408 | 1409 | var localizeOptions = cloneObject(options); 1410 | localizeOptions.addSuffix = Boolean(options.addSuffix); 1411 | localizeOptions.comparison = comparison; 1412 | var dateLeft; 1413 | var dateRight; 1414 | 1415 | if (comparison > 0) { 1416 | dateLeft = toDate(dirtyBaseDate); 1417 | dateRight = toDate(dirtyDate); 1418 | } else { 1419 | dateLeft = toDate(dirtyDate); 1420 | dateRight = toDate(dirtyBaseDate); 1421 | } 1422 | 1423 | var roundingMethod = options.roundingMethod == null ? 'round' : String(options.roundingMethod); 1424 | var roundingMethodFn; 1425 | 1426 | if (roundingMethod === 'floor') { 1427 | roundingMethodFn = Math.floor; 1428 | } else if (roundingMethod === 'ceil') { 1429 | roundingMethodFn = Math.ceil; 1430 | } else if (roundingMethod === 'round') { 1431 | roundingMethodFn = Math.round; 1432 | } else { 1433 | throw new RangeError("roundingMethod must be 'floor', 'ceil' or 'round'"); 1434 | } 1435 | 1436 | var milliseconds = dateRight.getTime() - dateLeft.getTime(); 1437 | var minutes = milliseconds / MILLISECONDS_IN_MINUTE; 1438 | var timezoneOffset = getTimezoneOffsetInMilliseconds(dateRight) - getTimezoneOffsetInMilliseconds(dateLeft); // Use DST-normalized difference in minutes for years, months and days; 1439 | // use regular difference in minutes for hours, minutes and seconds. 1440 | 1441 | var dstNormalizedMinutes = (milliseconds - timezoneOffset) / MILLISECONDS_IN_MINUTE; 1442 | var unit; 1443 | 1444 | if (options.unit == null) { 1445 | if (minutes < 1) { 1446 | unit = 'second'; 1447 | } else if (minutes < 60) { 1448 | unit = 'minute'; 1449 | } else if (minutes < MINUTES_IN_DAY) { 1450 | unit = 'hour'; 1451 | } else if (dstNormalizedMinutes < MINUTES_IN_MONTH) { 1452 | unit = 'day'; 1453 | } else if (dstNormalizedMinutes < MINUTES_IN_YEAR) { 1454 | unit = 'month'; 1455 | } else { 1456 | unit = 'year'; 1457 | } 1458 | } else { 1459 | unit = String(options.unit); 1460 | } // 0 up to 60 seconds 1461 | 1462 | 1463 | if (unit === 'second') { 1464 | var seconds = roundingMethodFn(milliseconds / 1000); 1465 | return locale.formatDistance('xSeconds', seconds, localizeOptions); // 1 up to 60 mins 1466 | } else if (unit === 'minute') { 1467 | var roundedMinutes = roundingMethodFn(minutes); 1468 | return locale.formatDistance('xMinutes', roundedMinutes, localizeOptions); // 1 up to 24 hours 1469 | } else if (unit === 'hour') { 1470 | var hours = roundingMethodFn(minutes / 60); 1471 | return locale.formatDistance('xHours', hours, localizeOptions); // 1 up to 30 days 1472 | } else if (unit === 'day') { 1473 | var days = roundingMethodFn(dstNormalizedMinutes / MINUTES_IN_DAY); 1474 | return locale.formatDistance('xDays', days, localizeOptions); // 1 up to 12 months 1475 | } else if (unit === 'month') { 1476 | var months = roundingMethodFn(dstNormalizedMinutes / MINUTES_IN_MONTH); 1477 | return months === 12 && options.unit !== 'month' ? locale.formatDistance('xYears', 1, localizeOptions) : locale.formatDistance('xMonths', months, localizeOptions); // 1 year up to max Date 1478 | } else if (unit === 'year') { 1479 | var years = roundingMethodFn(dstNormalizedMinutes / MINUTES_IN_YEAR); 1480 | return locale.formatDistance('xYears', years, localizeOptions); 1481 | } 1482 | 1483 | throw new RangeError("unit must be 'second', 'minute', 'hour', 'day', 'month' or 'year'"); 1484 | } 1485 | 1486 | /** 1487 | * @name formatDistanceToNowStrict 1488 | * @category Common Helpers 1489 | * @summary Return the distance between the given date and now in words. 1490 | * @pure false 1491 | * 1492 | * @description 1493 | * Return the distance between the given dates in words, using strict units. 1494 | * This is like `formatDistance`, but does not use helpers like 'almost', 'over', 1495 | * 'less than' and the like. 1496 | * 1497 | * | Distance between dates | Result | 1498 | * |------------------------|---------------------| 1499 | * | 0 ... 59 secs | [0..59] seconds | 1500 | * | 1 ... 59 mins | [1..59] minutes | 1501 | * | 1 ... 23 hrs | [1..23] hours | 1502 | * | 1 ... 29 days | [1..29] days | 1503 | * | 1 ... 11 months | [1..11] months | 1504 | * | 1 ... N years | [1..N] years | 1505 | * 1506 | * @param {Date|Number} date - the given date 1507 | * @param {Object} [options] - an object with options. 1508 | * @param {Boolean} [options.addSuffix=false] - result indicates if the second date is earlier or later than the first 1509 | * @param {'second'|'minute'|'hour'|'day'|'month'|'year'} [options.unit] - if specified, will force a unit 1510 | * @param {'floor'|'ceil'|'round'} [options.roundingMethod='round'] - which way to round partial units 1511 | * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale} 1512 | * @returns {String} the distance in words 1513 | * @throws {TypeError} 1 argument required 1514 | * @throws {RangeError} `date` must not be Invalid Date 1515 | * @throws {RangeError} `options.locale` must contain `formatDistance` property 1516 | * 1517 | * @example 1518 | * // If today is 1 January 2015, what is the distance to 2 July 2014? 1519 | * var result = formatDistanceToNowStrict( 1520 | * new Date(2014, 6, 2) 1521 | * ) 1522 | * //=> '6 months' 1523 | * 1524 | * @example 1525 | * // If now is 1 January 2015 00:00:00, 1526 | * // what is the distance to 1 January 2015 00:00:15, including seconds? 1527 | * var result = formatDistanceToNowStrict( 1528 | * new Date(2015, 0, 1, 0, 0, 15) 1529 | * ) 1530 | * //=> '20 seconds' 1531 | * 1532 | * @example 1533 | * // If today is 1 January 2015, 1534 | * // what is the distance to 1 January 2016, with a suffix? 1535 | * var result = formatDistanceToNowStrict( 1536 | * new Date(2016, 0, 1), 1537 | * {addSuffix: true} 1538 | * ) 1539 | * //=> 'in 1 year' 1540 | * 1541 | * @example 1542 | * // If today is 28 January 2015, 1543 | * // what is the distance to 1 January 2015, in months, rounded up?? 1544 | * var result = formatDistanceToNowStrict(new Date(2015, 0, 1), { 1545 | * unit: 'month', 1546 | * roundingMethod: 'ceil' 1547 | * }) 1548 | * //=> '1 month' 1549 | * 1550 | * @example 1551 | * // If today is 1 January 2015, 1552 | * // what is the distance to 1 August 2016 in Esperanto? 1553 | * var eoLocale = require('date-fns/locale/eo') 1554 | * var result = formatDistanceToNowStrict( 1555 | * new Date(2016, 7, 1), 1556 | * {locale: eoLocale} 1557 | * ) 1558 | * //=> '1 jaro' 1559 | */ 1560 | 1561 | function formatDistanceToNowStrict(dirtyDate, dirtyOptions) { 1562 | requiredArgs(1, arguments); 1563 | return formatDistanceStrict(dirtyDate, Date.now(), dirtyOptions); 1564 | } 1565 | 1566 | /** 1567 | * Days in 1 week. 1568 | * 1569 | * @name daysInWeek 1570 | * @constant 1571 | * @type {number} 1572 | * @default 1573 | */ 1574 | /** 1575 | * Milliseconds in 1 minute 1576 | * 1577 | * @name millisecondsInMinute 1578 | * @constant 1579 | * @type {number} 1580 | * @default 1581 | */ 1582 | 1583 | var millisecondsInMinute = 60000; 1584 | /** 1585 | * Milliseconds in 1 hour 1586 | * 1587 | * @name millisecondsInHour 1588 | * @constant 1589 | * @type {number} 1590 | * @default 1591 | */ 1592 | 1593 | var millisecondsInHour = 3600000; 1594 | 1595 | function toInteger(dirtyNumber) { 1596 | if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) { 1597 | return NaN; 1598 | } 1599 | 1600 | var number = Number(dirtyNumber); 1601 | 1602 | if (isNaN(number)) { 1603 | return number; 1604 | } 1605 | 1606 | return number < 0 ? Math.ceil(number) : Math.floor(number); 1607 | } 1608 | 1609 | /** 1610 | * @name parseISO 1611 | * @category Common Helpers 1612 | * @summary Parse ISO string 1613 | * 1614 | * @description 1615 | * Parse the given string in ISO 8601 format and return an instance of Date. 1616 | * 1617 | * Function accepts complete ISO 8601 formats as well as partial implementations. 1618 | * ISO 8601: http://en.wikipedia.org/wiki/ISO_8601 1619 | * 1620 | * If the argument isn't a string, the function cannot parse the string or 1621 | * the values are invalid, it returns Invalid Date. 1622 | * 1623 | * ### v2.0.0 breaking changes: 1624 | * 1625 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1626 | * 1627 | * - The previous `parse` implementation was renamed to `parseISO`. 1628 | * 1629 | * ```javascript 1630 | * // Before v2.0.0 1631 | * parse('2016-01-01') 1632 | * 1633 | * // v2.0.0 onward 1634 | * parseISO('2016-01-01') 1635 | * ``` 1636 | * 1637 | * - `parseISO` now validates separate date and time values in ISO-8601 strings 1638 | * and returns `Invalid Date` if the date is invalid. 1639 | * 1640 | * ```javascript 1641 | * parseISO('2018-13-32') 1642 | * //=> Invalid Date 1643 | * ``` 1644 | * 1645 | * - `parseISO` now doesn't fall back to `new Date` constructor 1646 | * if it fails to parse a string argument. Instead, it returns `Invalid Date`. 1647 | * 1648 | * @param {String} argument - the value to convert 1649 | * @param {Object} [options] - an object with options. 1650 | * @param {0|1|2} [options.additionalDigits=2] - the additional number of digits in the extended year format 1651 | * @returns {Date} the parsed date in the local time zone 1652 | * @throws {TypeError} 1 argument required 1653 | * @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2 1654 | * 1655 | * @example 1656 | * // Convert string '2014-02-11T11:30:30' to date: 1657 | * const result = parseISO('2014-02-11T11:30:30') 1658 | * //=> Tue Feb 11 2014 11:30:30 1659 | * 1660 | * @example 1661 | * // Convert string '+02014101' to date, 1662 | * // if the additional number of digits in the extended year format is 1: 1663 | * const result = parseISO('+02014101', { additionalDigits: 1 }) 1664 | * //=> Fri Apr 11 2014 00:00:00 1665 | */ 1666 | 1667 | function parseISO(argument, dirtyOptions) { 1668 | requiredArgs(1, arguments); 1669 | var options = dirtyOptions || {}; 1670 | var additionalDigits = options.additionalDigits == null ? 2 : toInteger(options.additionalDigits); 1671 | 1672 | if (additionalDigits !== 2 && additionalDigits !== 1 && additionalDigits !== 0) { 1673 | throw new RangeError('additionalDigits must be 0, 1 or 2'); 1674 | } 1675 | 1676 | if (!(typeof argument === 'string' || Object.prototype.toString.call(argument) === '[object String]')) { 1677 | return new Date(NaN); 1678 | } 1679 | 1680 | var dateStrings = splitDateString(argument); 1681 | var date; 1682 | 1683 | if (dateStrings.date) { 1684 | var parseYearResult = parseYear(dateStrings.date, additionalDigits); 1685 | date = parseDate(parseYearResult.restDateString, parseYearResult.year); 1686 | } 1687 | 1688 | if (!date || isNaN(date.getTime())) { 1689 | return new Date(NaN); 1690 | } 1691 | 1692 | var timestamp = date.getTime(); 1693 | var time = 0; 1694 | var offset; 1695 | 1696 | if (dateStrings.time) { 1697 | time = parseTime(dateStrings.time); 1698 | 1699 | if (isNaN(time)) { 1700 | return new Date(NaN); 1701 | } 1702 | } 1703 | 1704 | if (dateStrings.timezone) { 1705 | offset = parseTimezone(dateStrings.timezone); 1706 | 1707 | if (isNaN(offset)) { 1708 | return new Date(NaN); 1709 | } 1710 | } else { 1711 | var dirtyDate = new Date(timestamp + time); // js parsed string assuming it's in UTC timezone 1712 | // but we need it to be parsed in our timezone 1713 | // so we use utc values to build date in our timezone. 1714 | // Year values from 0 to 99 map to the years 1900 to 1999 1715 | // so set year explicitly with setFullYear. 1716 | 1717 | var result = new Date(0); 1718 | result.setFullYear(dirtyDate.getUTCFullYear(), dirtyDate.getUTCMonth(), dirtyDate.getUTCDate()); 1719 | result.setHours(dirtyDate.getUTCHours(), dirtyDate.getUTCMinutes(), dirtyDate.getUTCSeconds(), dirtyDate.getUTCMilliseconds()); 1720 | return result; 1721 | } 1722 | 1723 | return new Date(timestamp + time + offset); 1724 | } 1725 | var patterns = { 1726 | dateTimeDelimiter: /[T ]/, 1727 | timeZoneDelimiter: /[Z ]/i, 1728 | timezone: /([Z+-].*)$/ 1729 | }; 1730 | var dateRegex = /^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/; 1731 | var timeRegex = /^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/; 1732 | var timezoneRegex = /^([+-])(\d{2})(?::?(\d{2}))?$/; 1733 | 1734 | function splitDateString(dateString) { 1735 | var dateStrings = {}; 1736 | var array = dateString.split(patterns.dateTimeDelimiter); 1737 | var timeString; // The regex match should only return at maximum two array elements. 1738 | // [date], [time], or [date, time]. 1739 | 1740 | if (array.length > 2) { 1741 | return dateStrings; 1742 | } 1743 | 1744 | if (/:/.test(array[0])) { 1745 | timeString = array[0]; 1746 | } else { 1747 | dateStrings.date = array[0]; 1748 | timeString = array[1]; 1749 | 1750 | if (patterns.timeZoneDelimiter.test(dateStrings.date)) { 1751 | dateStrings.date = dateString.split(patterns.timeZoneDelimiter)[0]; 1752 | timeString = dateString.substr(dateStrings.date.length, dateString.length); 1753 | } 1754 | } 1755 | 1756 | if (timeString) { 1757 | var token = patterns.timezone.exec(timeString); 1758 | 1759 | if (token) { 1760 | dateStrings.time = timeString.replace(token[1], ''); 1761 | dateStrings.timezone = token[1]; 1762 | } else { 1763 | dateStrings.time = timeString; 1764 | } 1765 | } 1766 | 1767 | return dateStrings; 1768 | } 1769 | 1770 | function parseYear(dateString, additionalDigits) { 1771 | var regex = new RegExp('^(?:(\\d{4}|[+-]\\d{' + (4 + additionalDigits) + '})|(\\d{2}|[+-]\\d{' + (2 + additionalDigits) + '})$)'); 1772 | var captures = dateString.match(regex); // Invalid ISO-formatted year 1773 | 1774 | if (!captures) return { 1775 | year: NaN, 1776 | restDateString: '' 1777 | }; 1778 | var year = captures[1] ? parseInt(captures[1]) : null; 1779 | var century = captures[2] ? parseInt(captures[2]) : null; // either year or century is null, not both 1780 | 1781 | return { 1782 | year: century === null ? year : century * 100, 1783 | restDateString: dateString.slice((captures[1] || captures[2]).length) 1784 | }; 1785 | } 1786 | 1787 | function parseDate(dateString, year) { 1788 | // Invalid ISO-formatted year 1789 | if (year === null) return new Date(NaN); 1790 | var captures = dateString.match(dateRegex); // Invalid ISO-formatted string 1791 | 1792 | if (!captures) return new Date(NaN); 1793 | var isWeekDate = !!captures[4]; 1794 | var dayOfYear = parseDateUnit(captures[1]); 1795 | var month = parseDateUnit(captures[2]) - 1; 1796 | var day = parseDateUnit(captures[3]); 1797 | var week = parseDateUnit(captures[4]); 1798 | var dayOfWeek = parseDateUnit(captures[5]) - 1; 1799 | 1800 | if (isWeekDate) { 1801 | if (!validateWeekDate(year, week, dayOfWeek)) { 1802 | return new Date(NaN); 1803 | } 1804 | 1805 | return dayOfISOWeekYear(year, week, dayOfWeek); 1806 | } else { 1807 | var date = new Date(0); 1808 | 1809 | if (!validateDate(year, month, day) || !validateDayOfYearDate(year, dayOfYear)) { 1810 | return new Date(NaN); 1811 | } 1812 | 1813 | date.setUTCFullYear(year, month, Math.max(dayOfYear, day)); 1814 | return date; 1815 | } 1816 | } 1817 | 1818 | function parseDateUnit(value) { 1819 | return value ? parseInt(value) : 1; 1820 | } 1821 | 1822 | function parseTime(timeString) { 1823 | var captures = timeString.match(timeRegex); 1824 | if (!captures) return NaN; // Invalid ISO-formatted time 1825 | 1826 | var hours = parseTimeUnit(captures[1]); 1827 | var minutes = parseTimeUnit(captures[2]); 1828 | var seconds = parseTimeUnit(captures[3]); 1829 | 1830 | if (!validateTime(hours, minutes, seconds)) { 1831 | return NaN; 1832 | } 1833 | 1834 | return hours * millisecondsInHour + minutes * millisecondsInMinute + seconds * 1000; 1835 | } 1836 | 1837 | function parseTimeUnit(value) { 1838 | return value && parseFloat(value.replace(',', '.')) || 0; 1839 | } 1840 | 1841 | function parseTimezone(timezoneString) { 1842 | if (timezoneString === 'Z') return 0; 1843 | var captures = timezoneString.match(timezoneRegex); 1844 | if (!captures) return 0; 1845 | var sign = captures[1] === '+' ? -1 : 1; 1846 | var hours = parseInt(captures[2]); 1847 | var minutes = captures[3] && parseInt(captures[3]) || 0; 1848 | 1849 | if (!validateTimezone(hours, minutes)) { 1850 | return NaN; 1851 | } 1852 | 1853 | return sign * (hours * millisecondsInHour + minutes * millisecondsInMinute); 1854 | } 1855 | 1856 | function dayOfISOWeekYear(isoWeekYear, week, day) { 1857 | var date = new Date(0); 1858 | date.setUTCFullYear(isoWeekYear, 0, 4); 1859 | var fourthOfJanuaryDay = date.getUTCDay() || 7; 1860 | var diff = (week - 1) * 7 + day + 1 - fourthOfJanuaryDay; 1861 | date.setUTCDate(date.getUTCDate() + diff); 1862 | return date; 1863 | } // Validation functions 1864 | // February is null to handle the leap year (using ||) 1865 | 1866 | 1867 | var daysInMonths = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 1868 | 1869 | function isLeapYearIndex(year) { 1870 | return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0; 1871 | } 1872 | 1873 | function validateDate(year, month, date) { 1874 | return month >= 0 && month <= 11 && date >= 1 && date <= (daysInMonths[month] || (isLeapYearIndex(year) ? 29 : 28)); 1875 | } 1876 | 1877 | function validateDayOfYearDate(year, dayOfYear) { 1878 | return dayOfYear >= 1 && dayOfYear <= (isLeapYearIndex(year) ? 366 : 365); 1879 | } 1880 | 1881 | function validateWeekDate(_year, week, day) { 1882 | return week >= 1 && week <= 53 && day >= 0 && day <= 6; 1883 | } 1884 | 1885 | function validateTime(hours, minutes, seconds) { 1886 | if (hours === 24) { 1887 | return minutes === 0 && seconds === 0; 1888 | } 1889 | 1890 | return seconds >= 0 && seconds < 60 && minutes >= 0 && minutes < 60 && hours >= 0 && hours < 25; 1891 | } 1892 | 1893 | function validateTimezone(_hours, minutes) { 1894 | return minutes >= 0 && minutes <= 59; 1895 | } 1896 | 1897 | /** 1898 | * @name isPast 1899 | * @category Common Helpers 1900 | * @summary Is the given date in the past? 1901 | * @pure false 1902 | * 1903 | * @description 1904 | * Is the given date in the past? 1905 | * 1906 | * > ⚠️ Please note that this function is not present in the FP submodule as 1907 | * > it uses `Date.now()` internally hence impure and can't be safely curried. 1908 | * 1909 | * ### v2.0.0 breaking changes: 1910 | * 1911 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). 1912 | * 1913 | * @param {Date|Number} date - the date to check 1914 | * @returns {Boolean} the date is in the past 1915 | * @throws {TypeError} 1 argument required 1916 | * 1917 | * @example 1918 | * // If today is 6 October 2014, is 2 July 2014 in the past? 1919 | * var result = isPast(new Date(2014, 6, 2)) 1920 | * //=> true 1921 | */ 1922 | 1923 | function isPast(dirtyDate) { 1924 | requiredArgs(1, arguments); 1925 | return toDate(dirtyDate).getTime() < Date.now(); 1926 | } 1927 | 1928 | let locale = null; 1929 | 1930 | function TimeAgo(Alpine) { 1931 | Alpine.directive("timeago", (el, { 1932 | expression, 1933 | modifiers 1934 | }, { 1935 | evaluateLater, 1936 | effect, 1937 | cleanup 1938 | }) => { 1939 | let evaluateDate = evaluateLater(expression); 1940 | 1941 | const render = date => { 1942 | if (typeof date === "string") { 1943 | date = parseISO(date); 1944 | } 1945 | 1946 | try { 1947 | if (modifiers.includes("strict")) { 1948 | let unit = modifiers.includes("unit") ? modifiers[modifiers.findIndex(modifier => modifier === "unit") + 1] || undefined : undefined; 1949 | 1950 | if (!["second", "minute", "hour", "day", "month", "year"].includes(unit)) { 1951 | unit = undefined; 1952 | } 1953 | 1954 | let roundingMethod = modifiers.includes("rounding") ? modifiers[modifiers.findIndex(modifier => modifier === "rounding") + 1] || undefined : undefined; 1955 | 1956 | if (!["floor", "ceil", "round"].includes(roundingMethod)) { 1957 | roundingMethod = undefined; 1958 | } 1959 | 1960 | el.textContent = formatDistanceToNowStrict(date, { 1961 | addSuffix: !modifiers.includes("pure"), 1962 | unit, 1963 | roundingMethod, 1964 | locale 1965 | }); 1966 | } else { 1967 | el.textContent = formatDistanceToNow(date, { 1968 | addSuffix: !modifiers.includes("pure"), 1969 | includeSeconds: modifiers.includes("seconds"), 1970 | locale 1971 | }); 1972 | } 1973 | 1974 | dispatch(date); 1975 | } catch (e) { 1976 | console.error(e); 1977 | } 1978 | }; 1979 | 1980 | let interval; 1981 | 1982 | const dispatch = date => { 1983 | el.dispatchEvent(new CustomEvent("timeago:render", { 1984 | detail: { 1985 | isPast: isPast(date) 1986 | }, 1987 | bubbles: false 1988 | })); 1989 | }; 1990 | 1991 | const setupInterval = date => { 1992 | let intervalDuration = 30000; 1993 | 1994 | if (modifiers.includes("seconds")) { 1995 | intervalDuration = 5000; 1996 | } 1997 | 1998 | interval = setInterval(() => { 1999 | render(date); 2000 | }, intervalDuration); 2001 | }; 2002 | 2003 | const intersectionObserver = new IntersectionObserver(entries => { 2004 | const [entry] = entries; 2005 | const { 2006 | isIntersecting 2007 | } = entry; 2008 | 2009 | if (isIntersecting) { 2010 | evaluateDate(date => { 2011 | if (!interval) { 2012 | setupInterval(date); 2013 | render(date); 2014 | } 2015 | }); 2016 | } else { 2017 | if (interval) { 2018 | clearInterval(interval); 2019 | interval = undefined; 2020 | } 2021 | } 2022 | }); 2023 | intersectionObserver.observe(el); 2024 | effect(() => { 2025 | evaluateDate(date => { 2026 | if (interval) { 2027 | clearInterval(interval); 2028 | } 2029 | 2030 | render(date); 2031 | setupInterval(date); 2032 | }); 2033 | }); 2034 | cleanup(() => clearInterval(interval)); 2035 | }); 2036 | Alpine.magic("timeago", () => (expression, pure, seconds, strictOptions) => { 2037 | if (pure == null) { 2038 | pure = false; 2039 | } 2040 | 2041 | if (seconds == null) { 2042 | seconds = false; 2043 | } 2044 | 2045 | if (strictOptions != null && (strictOptions["strict"] || undefined)) { 2046 | return formatDistanceToNowStrict(expression, { 2047 | addSuffix: !pure, 2048 | unit: strictOptions["unit"] || undefined, 2049 | roundingMethod: strictOptions["roundingMethod"] || undefined, 2050 | locale 2051 | }); 2052 | } 2053 | 2054 | return formatDistanceToNow(expression, { 2055 | addSuffix: !pure, 2056 | includeSeconds: seconds, 2057 | locale 2058 | }); 2059 | }); 2060 | } 2061 | 2062 | TimeAgo.configure = config => { 2063 | if (config.hasOwnProperty("locale") && typeof config.locale === "object") { 2064 | if (config.locale.hasOwnProperty("formatDistance")) { 2065 | locale = config.locale; 2066 | } 2067 | } 2068 | 2069 | return TimeAgo; 2070 | }; 2071 | 2072 | document.addEventListener('alpine:init', () => { 2073 | TimeAgo(window.Alpine); 2074 | }); 2075 | 2076 | })); 2077 | //# sourceMappingURL=alpine-timeago.js.map 2078 | -------------------------------------------------------------------------------- /dist/alpine-timeago.min.js: -------------------------------------------------------------------------------- 1 | !function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t){if(t.length1?"s":"")+" required, but only "+t.length+" present")}function t(t){e(1,arguments);var n=Object.prototype.toString.call(t);return t instanceof Date||"object"==typeof t&&"[object Date]"===n?new Date(t.getTime()):"number"==typeof t||"[object Number]"===n?new Date(t):("string"!=typeof t&&"[object String]"!==n||"undefined"==typeof console||(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule"),console.warn((new Error).stack)),new Date(NaN))}function n(n,a){e(2,arguments);var r=t(n),i=t(a),o=r.getTime()-i.getTime();return o<0?-1:o>0?1:o}function a(n,a){e(2,arguments);var r=t(n),i=t(a),o=r.getFullYear()-i.getFullYear(),u=r.getMonth()-i.getMonth();return 12*o+u}function r(n){e(1,arguments);var a=t(n);return a.setHours(23,59,59,999),a}function i(n){e(1,arguments);var a=t(n),r=a.getMonth();return a.setFullYear(a.getFullYear(),r+1,0),a.setHours(23,59,59,999),a}function o(n){e(1,arguments);var a=t(n);return r(a).getTime()===i(a).getTime()}function u(r,i){e(2,arguments);var u,s=t(r),d=t(i),l=n(s,d),c=Math.abs(a(s,d));if(c<1)u=0;else{1===s.getMonth()&&s.getDate()>27&&s.setDate(30),s.setMonth(s.getMonth()-l*c);var f=n(s,d)===-l;o(t(r))&&1===c&&1===n(r,d)&&(f=!1),u=l*(c-Number(f))}return 0===u?0:u}function s(n,a){return e(2,arguments),t(n).getTime()-t(a).getTime()}var d={ceil:Math.ceil,round:Math.round,floor:Math.floor,trunc:function(e){return e<0?Math.ceil(e):Math.floor(e)}};function l(e){return e?d[e]:d.trunc}function c(t,n,a){e(2,arguments);var r=s(t,n)/1e3;return l(null==a?void 0:a.roundingMethod)(r)}var f={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}},m=function(e,t,n){var a,r=f[e];return a="string"==typeof r?r:1===t?r.one:r.other.replace("{{count}}",t.toString()),null!=n&&n.addSuffix?n.comparison&&n.comparison>0?"in "+a:a+" ago":a};function h(e){return function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.width?String(t.width):e.defaultWidth,a=e.formats[n]||e.formats[e.defaultWidth];return a}}var g={date:h({formats:{full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},defaultWidth:"full"}),time:h({formats:{full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},defaultWidth:"full"}),dateTime:h({formats:{full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},defaultWidth:"full"})},v={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"},w=function(e,t,n,a){return v[e]};function y(e){return function(t,n){var a,r=n||{};if("formatting"===(r.context?String(r.context):"standalone")&&e.formattingValues){var i=e.defaultFormattingWidth||e.defaultWidth,o=r.width?String(r.width):i;a=e.formattingValues[o]||e.formattingValues[i]}else{var u=e.defaultWidth,s=r.width?String(r.width):e.defaultWidth;a=e.values[s]||e.values[u]}return a[e.argumentCallback?e.argumentCallback(t):t]}}var b={ordinalNumber:function(e,t){var n=Number(e),a=n%100;if(a>20||a<10)switch(a%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},era:y({values:{narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},defaultWidth:"wide"}),quarter:y({values:{narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},defaultWidth:"wide",argumentCallback:function(e){return e-1}}),month:y({values:{narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},defaultWidth:"wide"}),day:y({values:{narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},defaultWidth:"wide"}),dayPeriod:y({values:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},defaultWidth:"wide",formattingValues:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},defaultFormattingWidth:"wide"})};function p(e){return function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=n.width,r=a&&e.matchPatterns[a]||e.matchPatterns[e.defaultMatchWidth],i=t.match(r);if(!i)return null;var o,u=i[0],s=a&&e.parsePatterns[a]||e.parsePatterns[e.defaultParseWidth],d=Array.isArray(s)?D(s,(function(e){return e.test(u)})):M(s,(function(e){return e.test(u)}));o=e.valueCallback?e.valueCallback(d):d,o=n.valueCallback?n.valueCallback(o):o;var l=t.slice(u.length);return{value:o,rest:l}}}function M(e,t){for(var n in e)if(e.hasOwnProperty(n)&&t(e[n]))return n}function D(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},n=e.match(S.matchPattern);if(!n)return null;var a=n[0],r=e.match(S.parsePattern);if(!r)return null;var i=S.valueCallback?S.valueCallback(r[0]):r[0];i=t.valueCallback?t.valueCallback(i):i;var o=e.slice(a.length);return{value:i,rest:o}}),era:p({matchPatterns:{narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},defaultMatchWidth:"wide",parsePatterns:{any:[/^b/i,/^(a|c)/i]},defaultParseWidth:"any"}),quarter:p({matchPatterns:{narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},defaultMatchWidth:"wide",parsePatterns:{any:[/1/i,/2/i,/3/i,/4/i]},defaultParseWidth:"any",valueCallback:function(e){return e+1}}),month:p({matchPatterns:{narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},defaultParseWidth:"any"}),day:p({matchPatterns:{narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},defaultParseWidth:"any"}),dayPeriod:p({matchPatterns:{narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},defaultMatchWidth:"any",parsePatterns:{any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},defaultParseWidth:"any"})},T={code:"en-US",formatDistance:m,formatLong:g,formatRelative:w,localize:b,match:N,options:{weekStartsOn:0,firstWeekContainsDate:1}};function x(e){return function(e,t){if(null==e)throw new TypeError("assign requires that input parameter not be null or undefined");for(var n in t=t||{})Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}({},e)}function W(e){var t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()));return t.setUTCFullYear(e.getFullYear()),e.getTime()-t.getTime()}var P=1440,C=43200;function k(a,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e(2,arguments);var o=i.locale||T;if(!o.formatDistance)throw new RangeError("locale must contain formatDistance property");var s=n(a,r);if(isNaN(s))throw new RangeError("Invalid time value");var d,l,f=x(i);f.addSuffix=Boolean(i.addSuffix),f.comparison=s,s>0?(d=t(r),l=t(a)):(d=t(a),l=t(r));var m,h=c(l,d),g=(W(l)-W(d))/1e3,v=Math.round((h-g)/60);if(v<2)return i.includeSeconds?h<5?o.formatDistance("lessThanXSeconds",5,f):h<10?o.formatDistance("lessThanXSeconds",10,f):h<20?o.formatDistance("lessThanXSeconds",20,f):h<40?o.formatDistance("halfAMinute",null,f):h<60?o.formatDistance("lessThanXMinutes",1,f):o.formatDistance("xMinutes",1,f):0===v?o.formatDistance("lessThanXMinutes",1,f):o.formatDistance("xMinutes",v,f);if(v<45)return o.formatDistance("xMinutes",v,f);if(v<90)return o.formatDistance("aboutXHours",1,f);if(v2&&void 0!==arguments[2]?arguments[2]:{};e(2,arguments);var o=i.locale||T;if(!o.formatDistance)throw new RangeError("locale must contain localize.formatDistance property");var u=n(a,r);if(isNaN(u))throw new RangeError("Invalid time value");var s,d,l=x(i);l.addSuffix=Boolean(i.addSuffix),l.comparison=u,u>0?(s=t(r),d=t(a)):(s=t(a),d=t(r));var c,f=null==i.roundingMethod?"round":String(i.roundingMethod);if("floor"===f)c=Math.floor;else if("ceil"===f)c=Math.ceil;else{if("round"!==f)throw new RangeError("roundingMethod must be 'floor', 'ceil' or 'round'");c=Math.round}var m,h=d.getTime()-s.getTime(),g=h/F,v=W(d)-W(s),w=(h-v)/F;if("second"===(m=null==i.unit?g<1?"second":g<60?"minute":g2)return n;if(/:/.test(a[0])?t=a[0]:(n.date=a[0],t=a[1],z.timeZoneDelimiter.test(n.date)&&(n.date=e.split(z.timeZoneDelimiter)[0],t=e.substr(n.date.length,e.length))),t){var r=z.timezone.exec(t);r?(n.time=t.replace(r[1],""),n.timezone=r[1]):n.time=t}return n}function Z(e,t){var n=new RegExp("^(?:(\\d{4}|[+-]\\d{"+(4+t)+"})|(\\d{2}|[+-]\\d{"+(2+t)+"})$)"),a=e.match(n);if(!a)return{year:NaN,restDateString:""};var r=a[1]?parseInt(a[1]):null,i=a[2]?parseInt(a[2]):null;return{year:null===i?r:100*i,restDateString:e.slice((a[1]||a[2]).length)}}function B(e,t){if(null===t)return new Date(NaN);var n=e.match(q);if(!n)return new Date(NaN);var a=!!n[4],r=$(n[1]),i=$(n[2])-1,o=$(n[3]),u=$(n[4]),s=$(n[5])-1;if(a)return function(e,t,n){return t>=1&&t<=53&&n>=0&&n<=6}(0,u,s)?function(e,t,n){var a=new Date(0);a.setUTCFullYear(e,0,4);var r=a.getUTCDay()||7,i=7*(t-1)+n+1-r;return a.setUTCDate(a.getUTCDate()+i),a}(t,u,s):new Date(NaN);var d=new Date(0);return function(e,t,n){return t>=0&&t<=11&&n>=1&&n<=(G[t]||(K(e)?29:28))}(t,i,o)&&function(e,t){return t>=1&&t<=(K(e)?366:365)}(t,r)?(d.setUTCFullYear(t,i,Math.max(r,o)),d):new Date(NaN)}function $(e){return e?parseInt(e):1}function Q(e){var t=e.match(H);if(!t)return NaN;var n=V(t[1]),a=V(t[2]),r=V(t[3]);return function(e,t,n){if(24===e)return 0===t&&0===n;return n>=0&&n<60&&t>=0&&t<60&&e>=0&&e<25}(n,a,r)?n*U+6e4*a+1e3*r:NaN}function V(e){return e&&parseFloat(e.replace(",","."))||0}function L(e){if("Z"===e)return 0;var t=e.match(J);if(!t)return 0;var n="+"===t[1]?-1:1,a=parseInt(t[2]),r=t[3]&&parseInt(t[3])||0;return function(e,t){return t>=0&&t<=59}(0,r)?n*(a*U+6e4*r):NaN}var G=[31,null,31,30,31,30,31,31,30,31,30,31];function K(e){return e%400==0||e%4==0&&e%100!=0}function _(n){return e(1,arguments),t(n).getTime(){let u=r(n);const s=n=>{"string"==typeof n&&(n=function(t,n){e(1,arguments);var a=n||{},r=null==a.additionalDigits?2:O(a.additionalDigits);if(2!==r&&1!==r&&0!==r)throw new RangeError("additionalDigits must be 0, 1 or 2");if("string"!=typeof t&&"[object String]"!==Object.prototype.toString.call(t))return new Date(NaN);var i,o=R(t);if(o.date){var u=Z(o.date,r);i=B(u.restDateString,u.year)}if(!i||isNaN(i.getTime()))return new Date(NaN);var s,d=i.getTime(),l=0;if(o.time&&(l=Q(o.time),isNaN(l)))return new Date(NaN);if(!o.timezone){var c=new Date(d+l),f=new Date(0);return f.setFullYear(c.getUTCFullYear(),c.getUTCMonth(),c.getUTCDate()),f.setHours(c.getUTCHours(),c.getUTCMinutes(),c.getUTCSeconds(),c.getUTCMilliseconds()),f}return s=L(o.timezone),isNaN(s)?new Date(NaN):new Date(d+l+s)}(n));try{if(a.includes("strict")){let e=a.includes("unit")&&a[a.findIndex((e=>"unit"===e))+1]||void 0;["second","minute","hour","day","month","year"].includes(e)||(e=void 0);let r=a.includes("rounding")&&a[a.findIndex((e=>"rounding"===e))+1]||void 0;["floor","ceil","round"].includes(r)||(r=void 0),t.textContent=A(n,{addSuffix:!a.includes("pure"),unit:e,roundingMethod:r,locale:ee})}else t.textContent=j(n,{addSuffix:!a.includes("pure"),includeSeconds:a.includes("seconds"),locale:ee});l(n)}catch(e){console.error(e)}};let d;const l=e=>{t.dispatchEvent(new CustomEvent("timeago:render",{detail:{isPast:_(e)},bubbles:!1}))},c=e=>{let t=3e4;a.includes("seconds")&&(t=5e3),d=setInterval((()=>{s(e)}),t)};new IntersectionObserver((e=>{const[t]=e,{isIntersecting:n}=t;n?u((e=>{d||(c(e),s(e))})):d&&(clearInterval(d),d=void 0)})).observe(t),i((()=>{u((e=>{d&&clearInterval(d),s(e),c(e)}))})),o((()=>clearInterval(d)))})),t.magic("timeago",(()=>(e,t,n,a)=>(null==t&&(t=!1),null==n&&(n=!1),null!=a&&a.strict?A(e,{addSuffix:!t,unit:a.unit||void 0,roundingMethod:a.roundingMethod||void 0,locale:ee}):j(e,{addSuffix:!t,includeSeconds:n,locale:ee}))))}te.configure=e=>(e.hasOwnProperty("locale")&&"object"==typeof e.locale&&e.locale.hasOwnProperty("formatDistance")&&(ee=e.locale),te),document.addEventListener("alpine:init",(()=>{te(window.Alpine)}))})); 2 | //# sourceMappingURL=alpine-timeago.min.js.map 3 | -------------------------------------------------------------------------------- /dist/alpine-timeago.min.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"alpine-timeago.min.js","sources":["../node_modules/date-fns/esm/_lib/requiredArgs/index.js","../node_modules/date-fns/esm/toDate/index.js","../node_modules/date-fns/esm/compareAsc/index.js","../node_modules/date-fns/esm/differenceInCalendarMonths/index.js","../node_modules/date-fns/esm/endOfDay/index.js","../node_modules/date-fns/esm/endOfMonth/index.js","../node_modules/date-fns/esm/isLastDayOfMonth/index.js","../node_modules/date-fns/esm/differenceInMonths/index.js","../node_modules/date-fns/esm/differenceInMilliseconds/index.js","../node_modules/date-fns/esm/_lib/roundingMethods/index.js","../node_modules/date-fns/esm/differenceInSeconds/index.js","../node_modules/date-fns/esm/locale/en-US/_lib/formatDistance/index.js","../node_modules/date-fns/esm/locale/_lib/buildFormatLongFn/index.js","../node_modules/date-fns/esm/locale/en-US/_lib/formatLong/index.js","../node_modules/date-fns/esm/locale/en-US/_lib/formatRelative/index.js","../node_modules/date-fns/esm/locale/_lib/buildLocalizeFn/index.js","../node_modules/date-fns/esm/locale/en-US/_lib/localize/index.js","../node_modules/date-fns/esm/locale/_lib/buildMatchFn/index.js","../node_modules/date-fns/esm/locale/en-US/_lib/match/index.js","../node_modules/date-fns/esm/locale/_lib/buildMatchPatternFn/index.js","../node_modules/date-fns/esm/locale/en-US/index.js","../node_modules/date-fns/esm/_lib/cloneObject/index.js","../node_modules/date-fns/esm/_lib/assign/index.js","../node_modules/date-fns/esm/_lib/getTimezoneOffsetInMilliseconds/index.js","../node_modules/date-fns/esm/formatDistance/index.js","../node_modules/date-fns/esm/formatDistanceToNow/index.js","../node_modules/date-fns/esm/formatDistanceStrict/index.js","../node_modules/date-fns/esm/formatDistanceToNowStrict/index.js","../node_modules/date-fns/esm/constants/index.js","../node_modules/date-fns/esm/_lib/toInteger/index.js","../node_modules/date-fns/esm/parseISO/index.js","../node_modules/date-fns/esm/isPast/index.js","../src/index.js","../builds/cdn.js"],"sourcesContent":["export default function requiredArgs(required, args) {\n if (args.length < required) {\n throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');\n }\n}","import requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name toDate\n * @category Common Helpers\n * @summary Convert the given argument to an instance of Date.\n *\n * @description\n * Convert the given argument to an instance of Date.\n *\n * If the argument is an instance of Date, the function returns its clone.\n *\n * If the argument is a number, it is treated as a timestamp.\n *\n * If the argument is none of the above, the function returns Invalid Date.\n *\n * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.\n *\n * @param {Date|Number} argument - the value to convert\n * @returns {Date} the parsed date in the local time zone\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // Clone the date:\n * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))\n * //=> Tue Feb 11 2014 11:30:30\n *\n * @example\n * // Convert the timestamp to date:\n * const result = toDate(1392098430000)\n * //=> Tue Feb 11 2014 11:30:30\n */\n\nexport default function toDate(argument) {\n requiredArgs(1, arguments);\n var argStr = Object.prototype.toString.call(argument); // Clone the date\n\n if (argument instanceof Date || typeof argument === 'object' && argStr === '[object Date]') {\n // Prevent the date to lose the milliseconds when passed to new Date() in IE10\n return new Date(argument.getTime());\n } else if (typeof argument === 'number' || argStr === '[object Number]') {\n return new Date(argument);\n } else {\n if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') {\n // eslint-disable-next-line no-console\n console.warn(\"Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule\"); // eslint-disable-next-line no-console\n\n console.warn(new Error().stack);\n }\n\n return new Date(NaN);\n }\n}","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name compareAsc\n * @category Common Helpers\n * @summary Compare the two dates and return -1, 0 or 1.\n *\n * @description\n * Compare the two dates and return 1 if the first date is after the second,\n * -1 if the first date is before the second or 0 if dates are equal.\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * @param {Date|Number} dateLeft - the first date to compare\n * @param {Date|Number} dateRight - the second date to compare\n * @returns {Number} the result of the comparison\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // Compare 11 February 1987 and 10 July 1989:\n * const result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10))\n * //=> -1\n *\n * @example\n * // Sort the array of dates:\n * const result = [\n * new Date(1995, 6, 2),\n * new Date(1987, 1, 11),\n * new Date(1989, 6, 10)\n * ].sort(compareAsc)\n * //=> [\n * // Wed Feb 11 1987 00:00:00,\n * // Mon Jul 10 1989 00:00:00,\n * // Sun Jul 02 1995 00:00:00\n * // ]\n */\n\nexport default function compareAsc(dirtyDateLeft, dirtyDateRight) {\n requiredArgs(2, arguments);\n var dateLeft = toDate(dirtyDateLeft);\n var dateRight = toDate(dirtyDateRight);\n var diff = dateLeft.getTime() - dateRight.getTime();\n\n if (diff < 0) {\n return -1;\n } else if (diff > 0) {\n return 1; // Return 0 if diff is 0; return NaN if diff is NaN\n } else {\n return diff;\n }\n}","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name differenceInCalendarMonths\n * @category Month Helpers\n * @summary Get the number of calendar months between the given dates.\n *\n * @description\n * Get the number of calendar months between the given dates.\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * @param {Date|Number} dateLeft - the later date\n * @param {Date|Number} dateRight - the earlier date\n * @returns {Number} the number of calendar months\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // How many calendar months are between 31 January 2014 and 1 September 2014?\n * var result = differenceInCalendarMonths(\n * new Date(2014, 8, 1),\n * new Date(2014, 0, 31)\n * )\n * //=> 8\n */\n\nexport default function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) {\n requiredArgs(2, arguments);\n var dateLeft = toDate(dirtyDateLeft);\n var dateRight = toDate(dirtyDateRight);\n var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear();\n var monthDiff = dateLeft.getMonth() - dateRight.getMonth();\n return yearDiff * 12 + monthDiff;\n}","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name endOfDay\n * @category Day Helpers\n * @summary Return the end of a day for the given date.\n *\n * @description\n * Return the end of a day for the given date.\n * The result will be in the local timezone.\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * @param {Date|Number} date - the original date\n * @returns {Date} the end of a day\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // The end of a day for 2 September 2014 11:55:00:\n * const result = endOfDay(new Date(2014, 8, 2, 11, 55, 0))\n * //=> Tue Sep 02 2014 23:59:59.999\n */\n\nexport default function endOfDay(dirtyDate) {\n requiredArgs(1, arguments);\n var date = toDate(dirtyDate);\n date.setHours(23, 59, 59, 999);\n return date;\n}","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name endOfMonth\n * @category Month Helpers\n * @summary Return the end of a month for the given date.\n *\n * @description\n * Return the end of a month for the given date.\n * The result will be in the local timezone.\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * @param {Date|Number} date - the original date\n * @returns {Date} the end of a month\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // The end of a month for 2 September 2014 11:55:00:\n * const result = endOfMonth(new Date(2014, 8, 2, 11, 55, 0))\n * //=> Tue Sep 30 2014 23:59:59.999\n */\n\nexport default function endOfMonth(dirtyDate) {\n requiredArgs(1, arguments);\n var date = toDate(dirtyDate);\n var month = date.getMonth();\n date.setFullYear(date.getFullYear(), month + 1, 0);\n date.setHours(23, 59, 59, 999);\n return date;\n}","import toDate from \"../toDate/index.js\";\nimport endOfDay from \"../endOfDay/index.js\";\nimport endOfMonth from \"../endOfMonth/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name isLastDayOfMonth\n * @category Month Helpers\n * @summary Is the given date the last day of a month?\n *\n * @description\n * Is the given date the last day of a month?\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * @param {Date|Number} date - the date to check\n * @returns {Boolean} the date is the last day of a month\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // Is 28 February 2014 the last day of a month?\n * var result = isLastDayOfMonth(new Date(2014, 1, 28))\n * //=> true\n */\n\nexport default function isLastDayOfMonth(dirtyDate) {\n requiredArgs(1, arguments);\n var date = toDate(dirtyDate);\n return endOfDay(date).getTime() === endOfMonth(date).getTime();\n}","import toDate from \"../toDate/index.js\";\nimport differenceInCalendarMonths from \"../differenceInCalendarMonths/index.js\";\nimport compareAsc from \"../compareAsc/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\nimport isLastDayOfMonth from \"../isLastDayOfMonth/index.js\";\n/**\n * @name differenceInMonths\n * @category Month Helpers\n * @summary Get the number of full months between the given dates.\n *\n * @description\n * Get the number of full months between the given dates using trunc as a default rounding method.\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * @param {Date|Number} dateLeft - the later date\n * @param {Date|Number} dateRight - the earlier date\n * @returns {Number} the number of full months\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // How many full months are between 31 January 2014 and 1 September 2014?\n * const result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31))\n * //=> 7\n */\n\nexport default function differenceInMonths(dirtyDateLeft, dirtyDateRight) {\n requiredArgs(2, arguments);\n var dateLeft = toDate(dirtyDateLeft);\n var dateRight = toDate(dirtyDateRight);\n var sign = compareAsc(dateLeft, dateRight);\n var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight));\n var result; // Check for the difference of less than month\n\n if (difference < 1) {\n result = 0;\n } else {\n if (dateLeft.getMonth() === 1 && dateLeft.getDate() > 27) {\n // This will check if the date is end of Feb and assign a higher end of month date\n // to compare it with Jan\n dateLeft.setDate(30);\n }\n\n dateLeft.setMonth(dateLeft.getMonth() - sign * difference); // Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full\n // If so, result must be decreased by 1 in absolute value\n\n var isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign; // Check for cases of one full calendar month\n\n if (isLastDayOfMonth(toDate(dirtyDateLeft)) && difference === 1 && compareAsc(dirtyDateLeft, dateRight) === 1) {\n isLastMonthNotFull = false;\n }\n\n result = sign * (difference - Number(isLastMonthNotFull));\n } // Prevent negative zero\n\n\n return result === 0 ? 0 : result;\n}","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name differenceInMilliseconds\n * @category Millisecond Helpers\n * @summary Get the number of milliseconds between the given dates.\n *\n * @description\n * Get the number of milliseconds between the given dates.\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * @param {Date|Number} dateLeft - the later date\n * @param {Date|Number} dateRight - the earlier date\n * @returns {Number} the number of milliseconds\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // How many milliseconds are between\n * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?\n * const result = differenceInMilliseconds(\n * new Date(2014, 6, 2, 12, 30, 21, 700),\n * new Date(2014, 6, 2, 12, 30, 20, 600)\n * )\n * //=> 1100\n */\n\nexport default function differenceInMilliseconds(dateLeft, dateRight) {\n requiredArgs(2, arguments);\n return toDate(dateLeft).getTime() - toDate(dateRight).getTime();\n}","var roundingMap = {\n ceil: Math.ceil,\n round: Math.round,\n floor: Math.floor,\n trunc: function (value) {\n return value < 0 ? Math.ceil(value) : Math.floor(value);\n } // Math.trunc is not supported by IE\n\n};\nvar defaultRoundingMethod = 'trunc';\nexport function getRoundingMethod(method) {\n return method ? roundingMap[method] : roundingMap[defaultRoundingMethod];\n}","import differenceInMilliseconds from \"../differenceInMilliseconds/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\nimport { getRoundingMethod } from \"../_lib/roundingMethods/index.js\";\n/**\n * @name differenceInSeconds\n * @category Second Helpers\n * @summary Get the number of seconds between the given dates.\n *\n * @description\n * Get the number of seconds between the given dates.\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * @param {Date|Number} dateLeft - the later date\n * @param {Date|Number} dateRight - the earlier date\n * @param {Object} [options] - an object with options.\n * @param {String} [options.roundingMethod='trunc'] - a rounding method (`ceil`, `floor`, `round` or `trunc`)\n * @returns {Number} the number of seconds\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // How many seconds are between\n * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?\n * const result = differenceInSeconds(\n * new Date(2014, 6, 2, 12, 30, 20, 0),\n * new Date(2014, 6, 2, 12, 30, 7, 999)\n * )\n * //=> 12\n */\n\nexport default function differenceInSeconds(dateLeft, dateRight, options) {\n requiredArgs(2, arguments);\n var diff = differenceInMilliseconds(dateLeft, dateRight) / 1000;\n return getRoundingMethod(options === null || options === void 0 ? void 0 : options.roundingMethod)(diff);\n}","var formatDistanceLocale = {\n lessThanXSeconds: {\n one: 'less than a second',\n other: 'less than {{count}} seconds'\n },\n xSeconds: {\n one: '1 second',\n other: '{{count}} seconds'\n },\n halfAMinute: 'half a minute',\n lessThanXMinutes: {\n one: 'less than a minute',\n other: 'less than {{count}} minutes'\n },\n xMinutes: {\n one: '1 minute',\n other: '{{count}} minutes'\n },\n aboutXHours: {\n one: 'about 1 hour',\n other: 'about {{count}} hours'\n },\n xHours: {\n one: '1 hour',\n other: '{{count}} hours'\n },\n xDays: {\n one: '1 day',\n other: '{{count}} days'\n },\n aboutXWeeks: {\n one: 'about 1 week',\n other: 'about {{count}} weeks'\n },\n xWeeks: {\n one: '1 week',\n other: '{{count}} weeks'\n },\n aboutXMonths: {\n one: 'about 1 month',\n other: 'about {{count}} months'\n },\n xMonths: {\n one: '1 month',\n other: '{{count}} months'\n },\n aboutXYears: {\n one: 'about 1 year',\n other: 'about {{count}} years'\n },\n xYears: {\n one: '1 year',\n other: '{{count}} years'\n },\n overXYears: {\n one: 'over 1 year',\n other: 'over {{count}} years'\n },\n almostXYears: {\n one: 'almost 1 year',\n other: 'almost {{count}} years'\n }\n};\n\nvar formatDistance = function (token, count, options) {\n var result;\n var tokenValue = formatDistanceLocale[token];\n\n if (typeof tokenValue === 'string') {\n result = tokenValue;\n } else if (count === 1) {\n result = tokenValue.one;\n } else {\n result = tokenValue.other.replace('{{count}}', count.toString());\n }\n\n if (options !== null && options !== void 0 && options.addSuffix) {\n if (options.comparison && options.comparison > 0) {\n return 'in ' + result;\n } else {\n return result + ' ago';\n }\n }\n\n return result;\n};\n\nexport default formatDistance;","export default function buildFormatLongFn(args) {\n return function () {\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n // TODO: Remove String()\n var width = options.width ? String(options.width) : args.defaultWidth;\n var format = args.formats[width] || args.formats[args.defaultWidth];\n return format;\n };\n}","import buildFormatLongFn from \"../../../_lib/buildFormatLongFn/index.js\";\nvar dateFormats = {\n full: 'EEEE, MMMM do, y',\n long: 'MMMM do, y',\n medium: 'MMM d, y',\n short: 'MM/dd/yyyy'\n};\nvar timeFormats = {\n full: 'h:mm:ss a zzzz',\n long: 'h:mm:ss a z',\n medium: 'h:mm:ss a',\n short: 'h:mm a'\n};\nvar dateTimeFormats = {\n full: \"{{date}} 'at' {{time}}\",\n long: \"{{date}} 'at' {{time}}\",\n medium: '{{date}}, {{time}}',\n short: '{{date}}, {{time}}'\n};\nvar formatLong = {\n date: buildFormatLongFn({\n formats: dateFormats,\n defaultWidth: 'full'\n }),\n time: buildFormatLongFn({\n formats: timeFormats,\n defaultWidth: 'full'\n }),\n dateTime: buildFormatLongFn({\n formats: dateTimeFormats,\n defaultWidth: 'full'\n })\n};\nexport default formatLong;","var formatRelativeLocale = {\n lastWeek: \"'last' eeee 'at' p\",\n yesterday: \"'yesterday at' p\",\n today: \"'today at' p\",\n tomorrow: \"'tomorrow at' p\",\n nextWeek: \"eeee 'at' p\",\n other: 'P'\n};\n\nvar formatRelative = function (token, _date, _baseDate, _options) {\n return formatRelativeLocale[token];\n};\n\nexport default formatRelative;","export default function buildLocalizeFn(args) {\n return function (dirtyIndex, dirtyOptions) {\n var options = dirtyOptions || {};\n var context = options.context ? String(options.context) : 'standalone';\n var valuesArray;\n\n if (context === 'formatting' && args.formattingValues) {\n var defaultWidth = args.defaultFormattingWidth || args.defaultWidth;\n var width = options.width ? String(options.width) : defaultWidth;\n valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];\n } else {\n var _defaultWidth = args.defaultWidth;\n\n var _width = options.width ? String(options.width) : args.defaultWidth;\n\n valuesArray = args.values[_width] || args.values[_defaultWidth];\n }\n\n var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; // @ts-ignore: For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!\n\n return valuesArray[index];\n };\n}","import buildLocalizeFn from \"../../../_lib/buildLocalizeFn/index.js\";\nvar eraValues = {\n narrow: ['B', 'A'],\n abbreviated: ['BC', 'AD'],\n wide: ['Before Christ', 'Anno Domini']\n};\nvar quarterValues = {\n narrow: ['1', '2', '3', '4'],\n abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'],\n wide: ['1st quarter', '2nd quarter', '3rd quarter', '4th quarter']\n}; // Note: in English, the names of days of the week and months are capitalized.\n// If you are making a new locale based on this one, check if the same is true for the language you're working on.\n// Generally, formatted dates should look like they are in the middle of a sentence,\n// e.g. in Spanish language the weekdays and months should be in the lowercase.\n\nvar monthValues = {\n narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],\n abbreviated: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],\n wide: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']\n};\nvar dayValues = {\n narrow: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],\n short: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],\n abbreviated: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],\n wide: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']\n};\nvar dayPeriodValues = {\n narrow: {\n am: 'a',\n pm: 'p',\n midnight: 'mi',\n noon: 'n',\n morning: 'morning',\n afternoon: 'afternoon',\n evening: 'evening',\n night: 'night'\n },\n abbreviated: {\n am: 'AM',\n pm: 'PM',\n midnight: 'midnight',\n noon: 'noon',\n morning: 'morning',\n afternoon: 'afternoon',\n evening: 'evening',\n night: 'night'\n },\n wide: {\n am: 'a.m.',\n pm: 'p.m.',\n midnight: 'midnight',\n noon: 'noon',\n morning: 'morning',\n afternoon: 'afternoon',\n evening: 'evening',\n night: 'night'\n }\n};\nvar formattingDayPeriodValues = {\n narrow: {\n am: 'a',\n pm: 'p',\n midnight: 'mi',\n noon: 'n',\n morning: 'in the morning',\n afternoon: 'in the afternoon',\n evening: 'in the evening',\n night: 'at night'\n },\n abbreviated: {\n am: 'AM',\n pm: 'PM',\n midnight: 'midnight',\n noon: 'noon',\n morning: 'in the morning',\n afternoon: 'in the afternoon',\n evening: 'in the evening',\n night: 'at night'\n },\n wide: {\n am: 'a.m.',\n pm: 'p.m.',\n midnight: 'midnight',\n noon: 'noon',\n morning: 'in the morning',\n afternoon: 'in the afternoon',\n evening: 'in the evening',\n night: 'at night'\n }\n};\n\nvar ordinalNumber = function (dirtyNumber, _options) {\n var number = Number(dirtyNumber); // If ordinal numbers depend on context, for example,\n // if they are different for different grammatical genders,\n // use `options.unit`.\n //\n // `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',\n // 'day', 'hour', 'minute', 'second'.\n\n var rem100 = number % 100;\n\n if (rem100 > 20 || rem100 < 10) {\n switch (rem100 % 10) {\n case 1:\n return number + 'st';\n\n case 2:\n return number + 'nd';\n\n case 3:\n return number + 'rd';\n }\n }\n\n return number + 'th';\n};\n\nvar localize = {\n ordinalNumber: ordinalNumber,\n era: buildLocalizeFn({\n values: eraValues,\n defaultWidth: 'wide'\n }),\n quarter: buildLocalizeFn({\n values: quarterValues,\n defaultWidth: 'wide',\n argumentCallback: function (quarter) {\n return quarter - 1;\n }\n }),\n month: buildLocalizeFn({\n values: monthValues,\n defaultWidth: 'wide'\n }),\n day: buildLocalizeFn({\n values: dayValues,\n defaultWidth: 'wide'\n }),\n dayPeriod: buildLocalizeFn({\n values: dayPeriodValues,\n defaultWidth: 'wide',\n formattingValues: formattingDayPeriodValues,\n defaultFormattingWidth: 'wide'\n })\n};\nexport default localize;","export default function buildMatchFn(args) {\n return function (string) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var width = options.width;\n var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];\n var matchResult = string.match(matchPattern);\n\n if (!matchResult) {\n return null;\n }\n\n var matchedString = matchResult[0];\n var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];\n var key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, function (pattern) {\n return pattern.test(matchedString);\n }) : findKey(parsePatterns, function (pattern) {\n return pattern.test(matchedString);\n });\n var value;\n value = args.valueCallback ? args.valueCallback(key) : key;\n value = options.valueCallback ? options.valueCallback(value) : value;\n var rest = string.slice(matchedString.length);\n return {\n value: value,\n rest: rest\n };\n };\n}\n\nfunction findKey(object, predicate) {\n for (var key in object) {\n if (object.hasOwnProperty(key) && predicate(object[key])) {\n return key;\n }\n }\n\n return undefined;\n}\n\nfunction findIndex(array, predicate) {\n for (var key = 0; key < array.length; key++) {\n if (predicate(array[key])) {\n return key;\n }\n }\n\n return undefined;\n}","import buildMatchFn from \"../../../_lib/buildMatchFn/index.js\";\nimport buildMatchPatternFn from \"../../../_lib/buildMatchPatternFn/index.js\";\nvar matchOrdinalNumberPattern = /^(\\d+)(th|st|nd|rd)?/i;\nvar parseOrdinalNumberPattern = /\\d+/i;\nvar matchEraPatterns = {\n narrow: /^(b|a)/i,\n abbreviated: /^(b\\.?\\s?c\\.?|b\\.?\\s?c\\.?\\s?e\\.?|a\\.?\\s?d\\.?|c\\.?\\s?e\\.?)/i,\n wide: /^(before christ|before common era|anno domini|common era)/i\n};\nvar parseEraPatterns = {\n any: [/^b/i, /^(a|c)/i]\n};\nvar matchQuarterPatterns = {\n narrow: /^[1234]/i,\n abbreviated: /^q[1234]/i,\n wide: /^[1234](th|st|nd|rd)? quarter/i\n};\nvar parseQuarterPatterns = {\n any: [/1/i, /2/i, /3/i, /4/i]\n};\nvar matchMonthPatterns = {\n narrow: /^[jfmasond]/i,\n abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,\n wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i\n};\nvar parseMonthPatterns = {\n narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i],\n any: [/^ja/i, /^f/i, /^mar/i, /^ap/i, /^may/i, /^jun/i, /^jul/i, /^au/i, /^s/i, /^o/i, /^n/i, /^d/i]\n};\nvar matchDayPatterns = {\n narrow: /^[smtwf]/i,\n short: /^(su|mo|tu|we|th|fr|sa)/i,\n abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,\n wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i\n};\nvar parseDayPatterns = {\n narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],\n any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]\n};\nvar matchDayPeriodPatterns = {\n narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,\n any: /^([ap]\\.?\\s?m\\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i\n};\nvar parseDayPeriodPatterns = {\n any: {\n am: /^a/i,\n pm: /^p/i,\n midnight: /^mi/i,\n noon: /^no/i,\n morning: /morning/i,\n afternoon: /afternoon/i,\n evening: /evening/i,\n night: /night/i\n }\n};\nvar match = {\n ordinalNumber: buildMatchPatternFn({\n matchPattern: matchOrdinalNumberPattern,\n parsePattern: parseOrdinalNumberPattern,\n valueCallback: function (value) {\n return parseInt(value, 10);\n }\n }),\n era: buildMatchFn({\n matchPatterns: matchEraPatterns,\n defaultMatchWidth: 'wide',\n parsePatterns: parseEraPatterns,\n defaultParseWidth: 'any'\n }),\n quarter: buildMatchFn({\n matchPatterns: matchQuarterPatterns,\n defaultMatchWidth: 'wide',\n parsePatterns: parseQuarterPatterns,\n defaultParseWidth: 'any',\n valueCallback: function (index) {\n return index + 1;\n }\n }),\n month: buildMatchFn({\n matchPatterns: matchMonthPatterns,\n defaultMatchWidth: 'wide',\n parsePatterns: parseMonthPatterns,\n defaultParseWidth: 'any'\n }),\n day: buildMatchFn({\n matchPatterns: matchDayPatterns,\n defaultMatchWidth: 'wide',\n parsePatterns: parseDayPatterns,\n defaultParseWidth: 'any'\n }),\n dayPeriod: buildMatchFn({\n matchPatterns: matchDayPeriodPatterns,\n defaultMatchWidth: 'any',\n parsePatterns: parseDayPeriodPatterns,\n defaultParseWidth: 'any'\n })\n};\nexport default match;","export default function buildMatchPatternFn(args) {\n return function (string) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var matchResult = string.match(args.matchPattern);\n if (!matchResult) return null;\n var matchedString = matchResult[0];\n var parseResult = string.match(args.parsePattern);\n if (!parseResult) return null;\n var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];\n value = options.valueCallback ? options.valueCallback(value) : value;\n var rest = string.slice(matchedString.length);\n return {\n value: value,\n rest: rest\n };\n };\n}","import formatDistance from \"./_lib/formatDistance/index.js\";\nimport formatLong from \"./_lib/formatLong/index.js\";\nimport formatRelative from \"./_lib/formatRelative/index.js\";\nimport localize from \"./_lib/localize/index.js\";\nimport match from \"./_lib/match/index.js\";\n\n/**\n * @type {Locale}\n * @category Locales\n * @summary English locale (United States).\n * @language English\n * @iso-639-2 eng\n * @author Sasha Koss [@kossnocorp]{@link https://github.com/kossnocorp}\n * @author Lesha Koss [@leshakoss]{@link https://github.com/leshakoss}\n */\nvar locale = {\n code: 'en-US',\n formatDistance: formatDistance,\n formatLong: formatLong,\n formatRelative: formatRelative,\n localize: localize,\n match: match,\n options: {\n weekStartsOn: 0\n /* Sunday */\n ,\n firstWeekContainsDate: 1\n }\n};\nexport default locale;","import assign from \"../assign/index.js\";\nexport default function cloneObject(dirtyObject) {\n return assign({}, dirtyObject);\n}","export default function assign(target, dirtyObject) {\n if (target == null) {\n throw new TypeError('assign requires that input parameter not be null or undefined');\n }\n\n dirtyObject = dirtyObject || {};\n\n for (var property in dirtyObject) {\n if (Object.prototype.hasOwnProperty.call(dirtyObject, property)) {\n target[property] = dirtyObject[property];\n }\n }\n\n return target;\n}","/**\n * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.\n * They usually appear for dates that denote time before the timezones were introduced\n * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891\n * and GMT+01:00:00 after that date)\n *\n * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,\n * which would lead to incorrect calculations.\n *\n * This function returns the timezone offset in milliseconds that takes seconds in account.\n */\nexport default function getTimezoneOffsetInMilliseconds(date) {\n var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));\n utcDate.setUTCFullYear(date.getFullYear());\n return date.getTime() - utcDate.getTime();\n}","import compareAsc from \"../compareAsc/index.js\";\nimport differenceInMonths from \"../differenceInMonths/index.js\";\nimport differenceInSeconds from \"../differenceInSeconds/index.js\";\nimport defaultLocale from \"../locale/en-US/index.js\";\nimport toDate from \"../toDate/index.js\";\nimport cloneObject from \"../_lib/cloneObject/index.js\";\nimport getTimezoneOffsetInMilliseconds from \"../_lib/getTimezoneOffsetInMilliseconds/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\nvar MINUTES_IN_DAY = 1440;\nvar MINUTES_IN_ALMOST_TWO_DAYS = 2520;\nvar MINUTES_IN_MONTH = 43200;\nvar MINUTES_IN_TWO_MONTHS = 86400;\n/**\n * @name formatDistance\n * @category Common Helpers\n * @summary Return the distance between the given dates in words.\n *\n * @description\n * Return the distance between the given dates in words.\n *\n * | Distance between dates | Result |\n * |-------------------------------------------------------------------|---------------------|\n * | 0 ... 30 secs | less than a minute |\n * | 30 secs ... 1 min 30 secs | 1 minute |\n * | 1 min 30 secs ... 44 mins 30 secs | [2..44] minutes |\n * | 44 mins ... 30 secs ... 89 mins 30 secs | about 1 hour |\n * | 89 mins 30 secs ... 23 hrs 59 mins 30 secs | about [2..24] hours |\n * | 23 hrs 59 mins 30 secs ... 41 hrs 59 mins 30 secs | 1 day |\n * | 41 hrs 59 mins 30 secs ... 29 days 23 hrs 59 mins 30 secs | [2..30] days |\n * | 29 days 23 hrs 59 mins 30 secs ... 44 days 23 hrs 59 mins 30 secs | about 1 month |\n * | 44 days 23 hrs 59 mins 30 secs ... 59 days 23 hrs 59 mins 30 secs | about 2 months |\n * | 59 days 23 hrs 59 mins 30 secs ... 1 yr | [2..12] months |\n * | 1 yr ... 1 yr 3 months | about 1 year |\n * | 1 yr 3 months ... 1 yr 9 month s | over 1 year |\n * | 1 yr 9 months ... 2 yrs | almost 2 years |\n * | N yrs ... N yrs 3 months | about N years |\n * | N yrs 3 months ... N yrs 9 months | over N years |\n * | N yrs 9 months ... N+1 yrs | almost N+1 years |\n *\n * With `options.includeSeconds == true`:\n * | Distance between dates | Result |\n * |------------------------|----------------------|\n * | 0 secs ... 5 secs | less than 5 seconds |\n * | 5 secs ... 10 secs | less than 10 seconds |\n * | 10 secs ... 20 secs | less than 20 seconds |\n * | 20 secs ... 40 secs | half a minute |\n * | 40 secs ... 60 secs | less than a minute |\n * | 60 secs ... 90 secs | 1 minute |\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * - The function was renamed from `distanceInWords ` to `formatDistance`\n * to make its name consistent with `format` and `formatRelative`.\n *\n * - The order of arguments is swapped to make the function\n * consistent with `differenceIn...` functions.\n *\n * ```javascript\n * // Before v2.0.0\n *\n * distanceInWords(\n * new Date(1986, 3, 4, 10, 32, 0),\n * new Date(1986, 3, 4, 11, 32, 0),\n * { addSuffix: true }\n * ) //=> 'in about 1 hour'\n *\n * // v2.0.0 onward\n *\n * formatDistance(\n * new Date(1986, 3, 4, 11, 32, 0),\n * new Date(1986, 3, 4, 10, 32, 0),\n * { addSuffix: true }\n * ) //=> 'in about 1 hour'\n * ```\n *\n * @param {Date|Number} date - the date\n * @param {Date|Number} baseDate - the date to compare with\n * @param {Object} [options] - an object with options.\n * @param {Boolean} [options.includeSeconds=false] - distances less than a minute are more detailed\n * @param {Boolean} [options.addSuffix=false] - result indicates if the second date is earlier or later than the first\n * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}\n * @returns {String} the distance in words\n * @throws {TypeError} 2 arguments required\n * @throws {RangeError} `date` must not be Invalid Date\n * @throws {RangeError} `baseDate` must not be Invalid Date\n * @throws {RangeError} `options.locale` must contain `formatDistance` property\n *\n * @example\n * // What is the distance between 2 July 2014 and 1 January 2015?\n * const result = formatDistance(new Date(2014, 6, 2), new Date(2015, 0, 1))\n * //=> '6 months'\n *\n * @example\n * // What is the distance between 1 January 2015 00:00:15\n * // and 1 January 2015 00:00:00, including seconds?\n * const result = formatDistance(\n * new Date(2015, 0, 1, 0, 0, 15),\n * new Date(2015, 0, 1, 0, 0, 0),\n * { includeSeconds: true }\n * )\n * //=> 'less than 20 seconds'\n *\n * @example\n * // What is the distance from 1 January 2016\n * // to 1 January 2015, with a suffix?\n * const result = formatDistance(new Date(2015, 0, 1), new Date(2016, 0, 1), {\n * addSuffix: true\n * })\n * //=> 'about 1 year ago'\n *\n * @example\n * // What is the distance between 1 August 2016 and 1 January 2015 in Esperanto?\n * import { eoLocale } from 'date-fns/locale/eo'\n * const result = formatDistance(new Date(2016, 7, 1), new Date(2015, 0, 1), {\n * locale: eoLocale\n * })\n * //=> 'pli ol 1 jaro'\n */\n\nexport default function formatDistance(dirtyDate, dirtyBaseDate) {\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n requiredArgs(2, arguments);\n var locale = options.locale || defaultLocale;\n\n if (!locale.formatDistance) {\n throw new RangeError('locale must contain formatDistance property');\n }\n\n var comparison = compareAsc(dirtyDate, dirtyBaseDate);\n\n if (isNaN(comparison)) {\n throw new RangeError('Invalid time value');\n }\n\n var localizeOptions = cloneObject(options);\n localizeOptions.addSuffix = Boolean(options.addSuffix);\n localizeOptions.comparison = comparison;\n var dateLeft;\n var dateRight;\n\n if (comparison > 0) {\n dateLeft = toDate(dirtyBaseDate);\n dateRight = toDate(dirtyDate);\n } else {\n dateLeft = toDate(dirtyDate);\n dateRight = toDate(dirtyBaseDate);\n }\n\n var seconds = differenceInSeconds(dateRight, dateLeft);\n var offsetInSeconds = (getTimezoneOffsetInMilliseconds(dateRight) - getTimezoneOffsetInMilliseconds(dateLeft)) / 1000;\n var minutes = Math.round((seconds - offsetInSeconds) / 60);\n var months; // 0 up to 2 mins\n\n if (minutes < 2) {\n if (options.includeSeconds) {\n if (seconds < 5) {\n return locale.formatDistance('lessThanXSeconds', 5, localizeOptions);\n } else if (seconds < 10) {\n return locale.formatDistance('lessThanXSeconds', 10, localizeOptions);\n } else if (seconds < 20) {\n return locale.formatDistance('lessThanXSeconds', 20, localizeOptions);\n } else if (seconds < 40) {\n return locale.formatDistance('halfAMinute', null, localizeOptions);\n } else if (seconds < 60) {\n return locale.formatDistance('lessThanXMinutes', 1, localizeOptions);\n } else {\n return locale.formatDistance('xMinutes', 1, localizeOptions);\n }\n } else {\n if (minutes === 0) {\n return locale.formatDistance('lessThanXMinutes', 1, localizeOptions);\n } else {\n return locale.formatDistance('xMinutes', minutes, localizeOptions);\n }\n } // 2 mins up to 0.75 hrs\n\n } else if (minutes < 45) {\n return locale.formatDistance('xMinutes', minutes, localizeOptions); // 0.75 hrs up to 1.5 hrs\n } else if (minutes < 90) {\n return locale.formatDistance('aboutXHours', 1, localizeOptions); // 1.5 hrs up to 24 hrs\n } else if (minutes < MINUTES_IN_DAY) {\n var hours = Math.round(minutes / 60);\n return locale.formatDistance('aboutXHours', hours, localizeOptions); // 1 day up to 1.75 days\n } else if (minutes < MINUTES_IN_ALMOST_TWO_DAYS) {\n return locale.formatDistance('xDays', 1, localizeOptions); // 1.75 days up to 30 days\n } else if (minutes < MINUTES_IN_MONTH) {\n var days = Math.round(minutes / MINUTES_IN_DAY);\n return locale.formatDistance('xDays', days, localizeOptions); // 1 month up to 2 months\n } else if (minutes < MINUTES_IN_TWO_MONTHS) {\n months = Math.round(minutes / MINUTES_IN_MONTH);\n return locale.formatDistance('aboutXMonths', months, localizeOptions);\n }\n\n months = differenceInMonths(dateRight, dateLeft); // 2 months up to 12 months\n\n if (months < 12) {\n var nearestMonth = Math.round(minutes / MINUTES_IN_MONTH);\n return locale.formatDistance('xMonths', nearestMonth, localizeOptions); // 1 year up to max Date\n } else {\n var monthsSinceStartOfYear = months % 12;\n var years = Math.floor(months / 12); // N years up to 1 years 3 months\n\n if (monthsSinceStartOfYear < 3) {\n return locale.formatDistance('aboutXYears', years, localizeOptions); // N years 3 months up to N years 9 months\n } else if (monthsSinceStartOfYear < 9) {\n return locale.formatDistance('overXYears', years, localizeOptions); // N years 9 months up to N year 12 months\n } else {\n return locale.formatDistance('almostXYears', years + 1, localizeOptions);\n }\n }\n}","import distanceInWords from \"../formatDistance/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name formatDistanceToNow\n * @category Common Helpers\n * @summary Return the distance between the given date and now in words.\n * @pure false\n *\n * @description\n * Return the distance between the given date and now in words.\n *\n * | Distance to now | Result |\n * |-------------------------------------------------------------------|---------------------|\n * | 0 ... 30 secs | less than a minute |\n * | 30 secs ... 1 min 30 secs | 1 minute |\n * | 1 min 30 secs ... 44 mins 30 secs | [2..44] minutes |\n * | 44 mins ... 30 secs ... 89 mins 30 secs | about 1 hour |\n * | 89 mins 30 secs ... 23 hrs 59 mins 30 secs | about [2..24] hours |\n * | 23 hrs 59 mins 30 secs ... 41 hrs 59 mins 30 secs | 1 day |\n * | 41 hrs 59 mins 30 secs ... 29 days 23 hrs 59 mins 30 secs | [2..30] days |\n * | 29 days 23 hrs 59 mins 30 secs ... 44 days 23 hrs 59 mins 30 secs | about 1 month |\n * | 44 days 23 hrs 59 mins 30 secs ... 59 days 23 hrs 59 mins 30 secs | about 2 months |\n * | 59 days 23 hrs 59 mins 30 secs ... 1 yr | [2..12] months |\n * | 1 yr ... 1 yr 3 months | about 1 year |\n * | 1 yr 3 months ... 1 yr 9 month s | over 1 year |\n * | 1 yr 9 months ... 2 yrs | almost 2 years |\n * | N yrs ... N yrs 3 months | about N years |\n * | N yrs 3 months ... N yrs 9 months | over N years |\n * | N yrs 9 months ... N+1 yrs | almost N+1 years |\n *\n * With `options.includeSeconds == true`:\n * | Distance to now | Result |\n * |---------------------|----------------------|\n * | 0 secs ... 5 secs | less than 5 seconds |\n * | 5 secs ... 10 secs | less than 10 seconds |\n * | 10 secs ... 20 secs | less than 20 seconds |\n * | 20 secs ... 40 secs | half a minute |\n * | 40 secs ... 60 secs | less than a minute |\n * | 60 secs ... 90 secs | 1 minute |\n *\n * > ⚠️ Please note that this function is not present in the FP submodule as\n * > it uses `Date.now()` internally hence impure and can't be safely curried.\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * - The function was renamed from `distanceInWordsToNow ` to `formatDistanceToNow`\n * to make its name consistent with `format` and `formatRelative`.\n *\n * ```javascript\n * // Before v2.0.0\n *\n * distanceInWordsToNow(new Date(2014, 6, 2), { addSuffix: true })\n * //=> 'in 6 months'\n *\n * // v2.0.0 onward\n *\n * formatDistanceToNow(new Date(2014, 6, 2), { addSuffix: true })\n * //=> 'in 6 months'\n * ```\n *\n * @param {Date|Number} date - the given date\n * @param {Object} [options] - the object with options\n * @param {Boolean} [options.includeSeconds=false] - distances less than a minute are more detailed\n * @param {Boolean} [options.addSuffix=false] - result specifies if now is earlier or later than the passed date\n * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}\n * @returns {String} the distance in words\n * @throws {TypeError} 1 argument required\n * @throws {RangeError} `date` must not be Invalid Date\n * @throws {RangeError} `options.locale` must contain `formatDistance` property\n *\n * @example\n * // If today is 1 January 2015, what is the distance to 2 July 2014?\n * var result = formatDistanceToNow(\n * new Date(2014, 6, 2)\n * )\n * //=> '6 months'\n *\n * @example\n * // If now is 1 January 2015 00:00:00,\n * // what is the distance to 1 January 2015 00:00:15, including seconds?\n * var result = formatDistanceToNow(\n * new Date(2015, 0, 1, 0, 0, 15),\n * {includeSeconds: true}\n * )\n * //=> 'less than 20 seconds'\n *\n * @example\n * // If today is 1 January 2015,\n * // what is the distance to 1 January 2016, with a suffix?\n * var result = formatDistanceToNow(\n * new Date(2016, 0, 1),\n * {addSuffix: true}\n * )\n * //=> 'in about 1 year'\n *\n * @example\n * // If today is 1 January 2015,\n * // what is the distance to 1 August 2016 in Esperanto?\n * var eoLocale = require('date-fns/locale/eo')\n * var result = formatDistanceToNow(\n * new Date(2016, 7, 1),\n * {locale: eoLocale}\n * )\n * //=> 'pli ol 1 jaro'\n */\n\nexport default function formatDistanceToNow(dirtyDate, dirtyOptions) {\n requiredArgs(1, arguments);\n return distanceInWords(dirtyDate, Date.now(), dirtyOptions);\n}","import getTimezoneOffsetInMilliseconds from \"../_lib/getTimezoneOffsetInMilliseconds/index.js\";\nimport compareAsc from \"../compareAsc/index.js\";\nimport toDate from \"../toDate/index.js\";\nimport cloneObject from \"../_lib/cloneObject/index.js\";\nimport defaultLocale from \"../locale/en-US/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\nvar MILLISECONDS_IN_MINUTE = 1000 * 60;\nvar MINUTES_IN_DAY = 60 * 24;\nvar MINUTES_IN_MONTH = MINUTES_IN_DAY * 30;\nvar MINUTES_IN_YEAR = MINUTES_IN_DAY * 365;\n/**\n * @name formatDistanceStrict\n * @category Common Helpers\n * @summary Return the distance between the given dates in words.\n *\n * @description\n * Return the distance between the given dates in words, using strict units.\n * This is like `formatDistance`, but does not use helpers like 'almost', 'over',\n * 'less than' and the like.\n *\n * | Distance between dates | Result |\n * |------------------------|---------------------|\n * | 0 ... 59 secs | [0..59] seconds |\n * | 1 ... 59 mins | [1..59] minutes |\n * | 1 ... 23 hrs | [1..23] hours |\n * | 1 ... 29 days | [1..29] days |\n * | 1 ... 11 months | [1..11] months |\n * | 1 ... N years | [1..N] years |\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * - The function was renamed from `distanceInWordsStrict` to `formatDistanceStrict`\n * to make its name consistent with `format` and `formatRelative`.\n *\n * - The order of arguments is swapped to make the function\n * consistent with `differenceIn...` functions.\n *\n * ```javascript\n * // Before v2.0.0\n *\n * distanceInWordsStrict(\n * new Date(2015, 0, 2),\n * new Date(2014, 6, 2)\n * ) //=> '6 months'\n *\n * // v2.0.0 onward\n *\n * formatDistanceStrict(\n * new Date(2014, 6, 2),\n * new Date(2015, 0, 2)\n * ) //=> '6 months'\n * ```\n *\n * - `partialMethod` option is renamed to `roundingMethod`.\n *\n * ```javascript\n * // Before v2.0.0\n *\n * distanceInWordsStrict(\n * new Date(1986, 3, 4, 10, 32, 0),\n * new Date(1986, 3, 4, 10, 33, 1),\n * { partialMethod: 'ceil' }\n * ) //=> '2 minutes'\n *\n * // v2.0.0 onward\n *\n * formatDistanceStrict(\n * new Date(1986, 3, 4, 10, 33, 1),\n * new Date(1986, 3, 4, 10, 32, 0),\n * { roundingMethod: 'ceil' }\n * ) //=> '2 minutes'\n * ```\n *\n * - If `roundingMethod` is not specified, it now defaults to `round` instead of `floor`.\n *\n * - `unit` option now accepts one of the strings:\n * 'second', 'minute', 'hour', 'day', 'month' or 'year' instead of 's', 'm', 'h', 'd', 'M' or 'Y'\n *\n * ```javascript\n * // Before v2.0.0\n *\n * distanceInWordsStrict(\n * new Date(1986, 3, 4, 10, 32, 0),\n * new Date(1986, 3, 4, 10, 33, 1),\n * { unit: 'm' }\n * )\n *\n * // v2.0.0 onward\n *\n * formatDistanceStrict(\n * new Date(1986, 3, 4, 10, 33, 1),\n * new Date(1986, 3, 4, 10, 32, 0),\n * { unit: 'minute' }\n * )\n * ```\n *\n * @param {Date|Number} date - the date\n * @param {Date|Number} baseDate - the date to compare with\n * @param {Object} [options] - an object with options.\n * @param {Boolean} [options.addSuffix=false] - result indicates if the second date is earlier or later than the first\n * @param {'second'|'minute'|'hour'|'day'|'month'|'year'} [options.unit] - if specified, will force a unit\n * @param {'floor'|'ceil'|'round'} [options.roundingMethod='round'] - which way to round partial units\n * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}\n * @returns {String} the distance in words\n * @throws {TypeError} 2 arguments required\n * @throws {RangeError} `date` must not be Invalid Date\n * @throws {RangeError} `baseDate` must not be Invalid Date\n * @throws {RangeError} `options.roundingMethod` must be 'floor', 'ceil' or 'round'\n * @throws {RangeError} `options.unit` must be 'second', 'minute', 'hour', 'day', 'month' or 'year'\n * @throws {RangeError} `options.locale` must contain `formatDistance` property\n *\n * @example\n * // What is the distance between 2 July 2014 and 1 January 2015?\n * const result = formatDistanceStrict(new Date(2014, 6, 2), new Date(2015, 0, 2))\n * //=> '6 months'\n *\n * @example\n * // What is the distance between 1 January 2015 00:00:15\n * // and 1 January 2015 00:00:00?\n * const result = formatDistanceStrict(\n * new Date(2015, 0, 1, 0, 0, 15),\n * new Date(2015, 0, 1, 0, 0, 0)\n * )\n * //=> '15 seconds'\n *\n * @example\n * // What is the distance from 1 January 2016\n * // to 1 January 2015, with a suffix?\n * const result = formatDistanceStrict(new Date(2015, 0, 1), new Date(2016, 0, 1), {\n * addSuffix: true\n * })\n * //=> '1 year ago'\n *\n * @example\n * // What is the distance from 1 January 2016\n * // to 1 January 2015, in minutes?\n * const result = formatDistanceStrict(new Date(2016, 0, 1), new Date(2015, 0, 1), {\n * unit: 'minute'\n * })\n * //=> '525600 minutes'\n *\n * @example\n * // What is the distance from 1 January 2015\n * // to 28 January 2015, in months, rounded up?\n * const result = formatDistanceStrict(new Date(2015, 0, 28), new Date(2015, 0, 1), {\n * unit: 'month',\n * roundingMethod: 'ceil'\n * })\n * //=> '1 month'\n *\n * @example\n * // What is the distance between 1 August 2016 and 1 January 2015 in Esperanto?\n * import { eoLocale } from 'date-fns/locale/eo'\n * const result = formatDistanceStrict(new Date(2016, 7, 1), new Date(2015, 0, 1), {\n * locale: eoLocale\n * })\n * //=> '1 jaro'\n */\n\nexport default function formatDistanceStrict(dirtyDate, dirtyBaseDate) {\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n requiredArgs(2, arguments);\n var locale = options.locale || defaultLocale;\n\n if (!locale.formatDistance) {\n throw new RangeError('locale must contain localize.formatDistance property');\n }\n\n var comparison = compareAsc(dirtyDate, dirtyBaseDate);\n\n if (isNaN(comparison)) {\n throw new RangeError('Invalid time value');\n }\n\n var localizeOptions = cloneObject(options);\n localizeOptions.addSuffix = Boolean(options.addSuffix);\n localizeOptions.comparison = comparison;\n var dateLeft;\n var dateRight;\n\n if (comparison > 0) {\n dateLeft = toDate(dirtyBaseDate);\n dateRight = toDate(dirtyDate);\n } else {\n dateLeft = toDate(dirtyDate);\n dateRight = toDate(dirtyBaseDate);\n }\n\n var roundingMethod = options.roundingMethod == null ? 'round' : String(options.roundingMethod);\n var roundingMethodFn;\n\n if (roundingMethod === 'floor') {\n roundingMethodFn = Math.floor;\n } else if (roundingMethod === 'ceil') {\n roundingMethodFn = Math.ceil;\n } else if (roundingMethod === 'round') {\n roundingMethodFn = Math.round;\n } else {\n throw new RangeError(\"roundingMethod must be 'floor', 'ceil' or 'round'\");\n }\n\n var milliseconds = dateRight.getTime() - dateLeft.getTime();\n var minutes = milliseconds / MILLISECONDS_IN_MINUTE;\n var timezoneOffset = getTimezoneOffsetInMilliseconds(dateRight) - getTimezoneOffsetInMilliseconds(dateLeft); // Use DST-normalized difference in minutes for years, months and days;\n // use regular difference in minutes for hours, minutes and seconds.\n\n var dstNormalizedMinutes = (milliseconds - timezoneOffset) / MILLISECONDS_IN_MINUTE;\n var unit;\n\n if (options.unit == null) {\n if (minutes < 1) {\n unit = 'second';\n } else if (minutes < 60) {\n unit = 'minute';\n } else if (minutes < MINUTES_IN_DAY) {\n unit = 'hour';\n } else if (dstNormalizedMinutes < MINUTES_IN_MONTH) {\n unit = 'day';\n } else if (dstNormalizedMinutes < MINUTES_IN_YEAR) {\n unit = 'month';\n } else {\n unit = 'year';\n }\n } else {\n unit = String(options.unit);\n } // 0 up to 60 seconds\n\n\n if (unit === 'second') {\n var seconds = roundingMethodFn(milliseconds / 1000);\n return locale.formatDistance('xSeconds', seconds, localizeOptions); // 1 up to 60 mins\n } else if (unit === 'minute') {\n var roundedMinutes = roundingMethodFn(minutes);\n return locale.formatDistance('xMinutes', roundedMinutes, localizeOptions); // 1 up to 24 hours\n } else if (unit === 'hour') {\n var hours = roundingMethodFn(minutes / 60);\n return locale.formatDistance('xHours', hours, localizeOptions); // 1 up to 30 days\n } else if (unit === 'day') {\n var days = roundingMethodFn(dstNormalizedMinutes / MINUTES_IN_DAY);\n return locale.formatDistance('xDays', days, localizeOptions); // 1 up to 12 months\n } else if (unit === 'month') {\n var months = roundingMethodFn(dstNormalizedMinutes / MINUTES_IN_MONTH);\n return months === 12 && options.unit !== 'month' ? locale.formatDistance('xYears', 1, localizeOptions) : locale.formatDistance('xMonths', months, localizeOptions); // 1 year up to max Date\n } else if (unit === 'year') {\n var years = roundingMethodFn(dstNormalizedMinutes / MINUTES_IN_YEAR);\n return locale.formatDistance('xYears', years, localizeOptions);\n }\n\n throw new RangeError(\"unit must be 'second', 'minute', 'hour', 'day', 'month' or 'year'\");\n}","import formatDistanceStrict from \"../formatDistanceStrict/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name formatDistanceToNowStrict\n * @category Common Helpers\n * @summary Return the distance between the given date and now in words.\n * @pure false\n *\n * @description\n * Return the distance between the given dates in words, using strict units.\n * This is like `formatDistance`, but does not use helpers like 'almost', 'over',\n * 'less than' and the like.\n *\n * | Distance between dates | Result |\n * |------------------------|---------------------|\n * | 0 ... 59 secs | [0..59] seconds |\n * | 1 ... 59 mins | [1..59] minutes |\n * | 1 ... 23 hrs | [1..23] hours |\n * | 1 ... 29 days | [1..29] days |\n * | 1 ... 11 months | [1..11] months |\n * | 1 ... N years | [1..N] years |\n *\n * @param {Date|Number} date - the given date\n * @param {Object} [options] - an object with options.\n * @param {Boolean} [options.addSuffix=false] - result indicates if the second date is earlier or later than the first\n * @param {'second'|'minute'|'hour'|'day'|'month'|'year'} [options.unit] - if specified, will force a unit\n * @param {'floor'|'ceil'|'round'} [options.roundingMethod='round'] - which way to round partial units\n * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}\n * @returns {String} the distance in words\n * @throws {TypeError} 1 argument required\n * @throws {RangeError} `date` must not be Invalid Date\n * @throws {RangeError} `options.locale` must contain `formatDistance` property\n *\n * @example\n * // If today is 1 January 2015, what is the distance to 2 July 2014?\n * var result = formatDistanceToNowStrict(\n * new Date(2014, 6, 2)\n * )\n * //=> '6 months'\n *\n * @example\n * // If now is 1 January 2015 00:00:00,\n * // what is the distance to 1 January 2015 00:00:15, including seconds?\n * var result = formatDistanceToNowStrict(\n * new Date(2015, 0, 1, 0, 0, 15)\n * )\n * //=> '20 seconds'\n *\n * @example\n * // If today is 1 January 2015,\n * // what is the distance to 1 January 2016, with a suffix?\n * var result = formatDistanceToNowStrict(\n * new Date(2016, 0, 1),\n * {addSuffix: true}\n * )\n * //=> 'in 1 year'\n *\n * @example\n * // If today is 28 January 2015,\n * // what is the distance to 1 January 2015, in months, rounded up??\n * var result = formatDistanceToNowStrict(new Date(2015, 0, 1), {\n * unit: 'month',\n * roundingMethod: 'ceil'\n * })\n * //=> '1 month'\n *\n * @example\n * // If today is 1 January 2015,\n * // what is the distance to 1 August 2016 in Esperanto?\n * var eoLocale = require('date-fns/locale/eo')\n * var result = formatDistanceToNowStrict(\n * new Date(2016, 7, 1),\n * {locale: eoLocale}\n * )\n * //=> '1 jaro'\n */\n\nexport default function formatDistanceToNowStrict(dirtyDate, dirtyOptions) {\n requiredArgs(1, arguments);\n return formatDistanceStrict(dirtyDate, Date.now(), dirtyOptions);\n}","/**\n * Days in 1 week.\n *\n * @name daysInWeek\n * @constant\n * @type {number}\n * @default\n */\nexport var daysInWeek = 7;\n/**\n * Maximum allowed time.\n *\n * @name maxTime\n * @constant\n * @type {number}\n * @default\n */\n\nexport var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1000;\n/**\n * Milliseconds in 1 minute\n *\n * @name millisecondsInMinute\n * @constant\n * @type {number}\n * @default\n */\n\nexport var millisecondsInMinute = 60000;\n/**\n * Milliseconds in 1 hour\n *\n * @name millisecondsInHour\n * @constant\n * @type {number}\n * @default\n */\n\nexport var millisecondsInHour = 3600000;\n/**\n * Milliseconds in 1 second\n *\n * @name millisecondsInSecond\n * @constant\n * @type {number}\n * @default\n */\n\nexport var millisecondsInSecond = 1000;\n/**\n * Minimum allowed time.\n *\n * @name minTime\n * @constant\n * @type {number}\n * @default\n */\n\nexport var minTime = -maxTime;\n/**\n * Minutes in 1 hour\n *\n * @name minutesInHour\n * @constant\n * @type {number}\n * @default\n */\n\nexport var minutesInHour = 60;\n/**\n * Months in 1 quarter\n *\n * @name monthsInQuarter\n * @constant\n * @type {number}\n * @default\n */\n\nexport var monthsInQuarter = 3;\n/**\n * Months in 1 year\n *\n * @name monthsInYear\n * @constant\n * @type {number}\n * @default\n */\n\nexport var monthsInYear = 12;\n/**\n * Quarters in 1 year\n *\n * @name quartersInYear\n * @constant\n * @type {number}\n * @default\n */\n\nexport var quartersInYear = 4;\n/**\n * Seconds in 1 hour\n *\n * @name secondsInHour\n * @constant\n * @type {number}\n * @default\n */\n\nexport var secondsInHour = 3600;\n/**\n * Seconds in 1 minute\n *\n * @name secondsInMinute\n * @constant\n * @type {number}\n * @default\n */\n\nexport var secondsInMinute = 60;","export default function toInteger(dirtyNumber) {\n if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {\n return NaN;\n }\n\n var number = Number(dirtyNumber);\n\n if (isNaN(number)) {\n return number;\n }\n\n return number < 0 ? Math.ceil(number) : Math.floor(number);\n}","import { millisecondsInHour, millisecondsInMinute } from \"../constants/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\nimport toInteger from \"../_lib/toInteger/index.js\";\n/**\n * @name parseISO\n * @category Common Helpers\n * @summary Parse ISO string\n *\n * @description\n * Parse the given string in ISO 8601 format and return an instance of Date.\n *\n * Function accepts complete ISO 8601 formats as well as partial implementations.\n * ISO 8601: http://en.wikipedia.org/wiki/ISO_8601\n *\n * If the argument isn't a string, the function cannot parse the string or\n * the values are invalid, it returns Invalid Date.\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * - The previous `parse` implementation was renamed to `parseISO`.\n *\n * ```javascript\n * // Before v2.0.0\n * parse('2016-01-01')\n *\n * // v2.0.0 onward\n * parseISO('2016-01-01')\n * ```\n *\n * - `parseISO` now validates separate date and time values in ISO-8601 strings\n * and returns `Invalid Date` if the date is invalid.\n *\n * ```javascript\n * parseISO('2018-13-32')\n * //=> Invalid Date\n * ```\n *\n * - `parseISO` now doesn't fall back to `new Date` constructor\n * if it fails to parse a string argument. Instead, it returns `Invalid Date`.\n *\n * @param {String} argument - the value to convert\n * @param {Object} [options] - an object with options.\n * @param {0|1|2} [options.additionalDigits=2] - the additional number of digits in the extended year format\n * @returns {Date} the parsed date in the local time zone\n * @throws {TypeError} 1 argument required\n * @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2\n *\n * @example\n * // Convert string '2014-02-11T11:30:30' to date:\n * const result = parseISO('2014-02-11T11:30:30')\n * //=> Tue Feb 11 2014 11:30:30\n *\n * @example\n * // Convert string '+02014101' to date,\n * // if the additional number of digits in the extended year format is 1:\n * const result = parseISO('+02014101', { additionalDigits: 1 })\n * //=> Fri Apr 11 2014 00:00:00\n */\n\nexport default function parseISO(argument, dirtyOptions) {\n requiredArgs(1, arguments);\n var options = dirtyOptions || {};\n var additionalDigits = options.additionalDigits == null ? 2 : toInteger(options.additionalDigits);\n\n if (additionalDigits !== 2 && additionalDigits !== 1 && additionalDigits !== 0) {\n throw new RangeError('additionalDigits must be 0, 1 or 2');\n }\n\n if (!(typeof argument === 'string' || Object.prototype.toString.call(argument) === '[object String]')) {\n return new Date(NaN);\n }\n\n var dateStrings = splitDateString(argument);\n var date;\n\n if (dateStrings.date) {\n var parseYearResult = parseYear(dateStrings.date, additionalDigits);\n date = parseDate(parseYearResult.restDateString, parseYearResult.year);\n }\n\n if (!date || isNaN(date.getTime())) {\n return new Date(NaN);\n }\n\n var timestamp = date.getTime();\n var time = 0;\n var offset;\n\n if (dateStrings.time) {\n time = parseTime(dateStrings.time);\n\n if (isNaN(time)) {\n return new Date(NaN);\n }\n }\n\n if (dateStrings.timezone) {\n offset = parseTimezone(dateStrings.timezone);\n\n if (isNaN(offset)) {\n return new Date(NaN);\n }\n } else {\n var dirtyDate = new Date(timestamp + time); // js parsed string assuming it's in UTC timezone\n // but we need it to be parsed in our timezone\n // so we use utc values to build date in our timezone.\n // Year values from 0 to 99 map to the years 1900 to 1999\n // so set year explicitly with setFullYear.\n\n var result = new Date(0);\n result.setFullYear(dirtyDate.getUTCFullYear(), dirtyDate.getUTCMonth(), dirtyDate.getUTCDate());\n result.setHours(dirtyDate.getUTCHours(), dirtyDate.getUTCMinutes(), dirtyDate.getUTCSeconds(), dirtyDate.getUTCMilliseconds());\n return result;\n }\n\n return new Date(timestamp + time + offset);\n}\nvar patterns = {\n dateTimeDelimiter: /[T ]/,\n timeZoneDelimiter: /[Z ]/i,\n timezone: /([Z+-].*)$/\n};\nvar dateRegex = /^-?(?:(\\d{3})|(\\d{2})(?:-?(\\d{2}))?|W(\\d{2})(?:-?(\\d{1}))?|)$/;\nvar timeRegex = /^(\\d{2}(?:[.,]\\d*)?)(?::?(\\d{2}(?:[.,]\\d*)?))?(?::?(\\d{2}(?:[.,]\\d*)?))?$/;\nvar timezoneRegex = /^([+-])(\\d{2})(?::?(\\d{2}))?$/;\n\nfunction splitDateString(dateString) {\n var dateStrings = {};\n var array = dateString.split(patterns.dateTimeDelimiter);\n var timeString; // The regex match should only return at maximum two array elements.\n // [date], [time], or [date, time].\n\n if (array.length > 2) {\n return dateStrings;\n }\n\n if (/:/.test(array[0])) {\n timeString = array[0];\n } else {\n dateStrings.date = array[0];\n timeString = array[1];\n\n if (patterns.timeZoneDelimiter.test(dateStrings.date)) {\n dateStrings.date = dateString.split(patterns.timeZoneDelimiter)[0];\n timeString = dateString.substr(dateStrings.date.length, dateString.length);\n }\n }\n\n if (timeString) {\n var token = patterns.timezone.exec(timeString);\n\n if (token) {\n dateStrings.time = timeString.replace(token[1], '');\n dateStrings.timezone = token[1];\n } else {\n dateStrings.time = timeString;\n }\n }\n\n return dateStrings;\n}\n\nfunction parseYear(dateString, additionalDigits) {\n var regex = new RegExp('^(?:(\\\\d{4}|[+-]\\\\d{' + (4 + additionalDigits) + '})|(\\\\d{2}|[+-]\\\\d{' + (2 + additionalDigits) + '})$)');\n var captures = dateString.match(regex); // Invalid ISO-formatted year\n\n if (!captures) return {\n year: NaN,\n restDateString: ''\n };\n var year = captures[1] ? parseInt(captures[1]) : null;\n var century = captures[2] ? parseInt(captures[2]) : null; // either year or century is null, not both\n\n return {\n year: century === null ? year : century * 100,\n restDateString: dateString.slice((captures[1] || captures[2]).length)\n };\n}\n\nfunction parseDate(dateString, year) {\n // Invalid ISO-formatted year\n if (year === null) return new Date(NaN);\n var captures = dateString.match(dateRegex); // Invalid ISO-formatted string\n\n if (!captures) return new Date(NaN);\n var isWeekDate = !!captures[4];\n var dayOfYear = parseDateUnit(captures[1]);\n var month = parseDateUnit(captures[2]) - 1;\n var day = parseDateUnit(captures[3]);\n var week = parseDateUnit(captures[4]);\n var dayOfWeek = parseDateUnit(captures[5]) - 1;\n\n if (isWeekDate) {\n if (!validateWeekDate(year, week, dayOfWeek)) {\n return new Date(NaN);\n }\n\n return dayOfISOWeekYear(year, week, dayOfWeek);\n } else {\n var date = new Date(0);\n\n if (!validateDate(year, month, day) || !validateDayOfYearDate(year, dayOfYear)) {\n return new Date(NaN);\n }\n\n date.setUTCFullYear(year, month, Math.max(dayOfYear, day));\n return date;\n }\n}\n\nfunction parseDateUnit(value) {\n return value ? parseInt(value) : 1;\n}\n\nfunction parseTime(timeString) {\n var captures = timeString.match(timeRegex);\n if (!captures) return NaN; // Invalid ISO-formatted time\n\n var hours = parseTimeUnit(captures[1]);\n var minutes = parseTimeUnit(captures[2]);\n var seconds = parseTimeUnit(captures[3]);\n\n if (!validateTime(hours, minutes, seconds)) {\n return NaN;\n }\n\n return hours * millisecondsInHour + minutes * millisecondsInMinute + seconds * 1000;\n}\n\nfunction parseTimeUnit(value) {\n return value && parseFloat(value.replace(',', '.')) || 0;\n}\n\nfunction parseTimezone(timezoneString) {\n if (timezoneString === 'Z') return 0;\n var captures = timezoneString.match(timezoneRegex);\n if (!captures) return 0;\n var sign = captures[1] === '+' ? -1 : 1;\n var hours = parseInt(captures[2]);\n var minutes = captures[3] && parseInt(captures[3]) || 0;\n\n if (!validateTimezone(hours, minutes)) {\n return NaN;\n }\n\n return sign * (hours * millisecondsInHour + minutes * millisecondsInMinute);\n}\n\nfunction dayOfISOWeekYear(isoWeekYear, week, day) {\n var date = new Date(0);\n date.setUTCFullYear(isoWeekYear, 0, 4);\n var fourthOfJanuaryDay = date.getUTCDay() || 7;\n var diff = (week - 1) * 7 + day + 1 - fourthOfJanuaryDay;\n date.setUTCDate(date.getUTCDate() + diff);\n return date;\n} // Validation functions\n// February is null to handle the leap year (using ||)\n\n\nvar daysInMonths = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n\nfunction isLeapYearIndex(year) {\n return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;\n}\n\nfunction validateDate(year, month, date) {\n return month >= 0 && month <= 11 && date >= 1 && date <= (daysInMonths[month] || (isLeapYearIndex(year) ? 29 : 28));\n}\n\nfunction validateDayOfYearDate(year, dayOfYear) {\n return dayOfYear >= 1 && dayOfYear <= (isLeapYearIndex(year) ? 366 : 365);\n}\n\nfunction validateWeekDate(_year, week, day) {\n return week >= 1 && week <= 53 && day >= 0 && day <= 6;\n}\n\nfunction validateTime(hours, minutes, seconds) {\n if (hours === 24) {\n return minutes === 0 && seconds === 0;\n }\n\n return seconds >= 0 && seconds < 60 && minutes >= 0 && minutes < 60 && hours >= 0 && hours < 25;\n}\n\nfunction validateTimezone(_hours, minutes) {\n return minutes >= 0 && minutes <= 59;\n}","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name isPast\n * @category Common Helpers\n * @summary Is the given date in the past?\n * @pure false\n *\n * @description\n * Is the given date in the past?\n *\n * > ⚠️ Please note that this function is not present in the FP submodule as\n * > it uses `Date.now()` internally hence impure and can't be safely curried.\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * @param {Date|Number} date - the date to check\n * @returns {Boolean} the date is in the past\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // If today is 6 October 2014, is 2 July 2014 in the past?\n * var result = isPast(new Date(2014, 6, 2))\n * //=> true\n */\n\nexport default function isPast(dirtyDate) {\n requiredArgs(1, arguments);\n return toDate(dirtyDate).getTime() < Date.now();\n}","import formatDistanceToNow from \"date-fns/formatDistanceToNow\";\nimport formatDistanceToNowStrict from \"date-fns/formatDistanceToNowStrict\";\nimport parseISO from \"date-fns/parseISO\";\nimport isPast from \"date-fns/isPast\";\n\nlet locale = null;\n\nfunction TimeAgo(Alpine) {\n Alpine.directive(\n \"timeago\",\n (el, { expression, modifiers }, { evaluateLater, effect, cleanup }) => {\n let evaluateDate = evaluateLater(expression);\n\n const render = (date) => {\n if (typeof date === \"string\") {\n date = parseISO(date);\n }\n\n try {\n if (modifiers.includes(\"strict\")) {\n let unit = modifiers.includes(\"unit\")\n ? modifiers[\n modifiers.findIndex((modifier) => modifier === \"unit\") + 1\n ] || undefined\n : undefined;\n if (\n ![\"second\", \"minute\", \"hour\", \"day\", \"month\", \"year\"].includes(\n unit\n )\n ) {\n unit = undefined;\n }\n let roundingMethod = modifiers.includes(\"rounding\")\n ? modifiers[\n modifiers.findIndex((modifier) => modifier === \"rounding\") + 1\n ] || undefined\n : undefined;\n if (![\"floor\", \"ceil\", \"round\"].includes(roundingMethod)) {\n roundingMethod = undefined;\n }\n el.textContent = formatDistanceToNowStrict(date, {\n addSuffix: !modifiers.includes(\"pure\"),\n unit,\n roundingMethod,\n locale,\n });\n } else {\n el.textContent = formatDistanceToNow(date, {\n addSuffix: !modifiers.includes(\"pure\"),\n includeSeconds: modifiers.includes(\"seconds\"),\n locale,\n });\n }\n\n dispatch(date);\n } catch (e) {\n console.error(e);\n }\n };\n\n let interval;\n\n const dispatch = (date) => {\n el.dispatchEvent(new CustomEvent(\"timeago:render\", { detail: { isPast: isPast(date) }, bubbles: false }));\n };\n\n const setupInterval = (date) => {\n let intervalDuration = 30000;\n if (modifiers.includes(\"seconds\")) {\n intervalDuration = 5000;\n }\n\n interval = setInterval(() => {\n render(date);\n }, intervalDuration);\n };\n\n const intersectionObserver = new IntersectionObserver((entries) => {\n const [entry] = entries;\n const {isIntersecting} = entry;\n if (isIntersecting) {\n evaluateDate((date) => {\n if (!interval) {\n setupInterval(date);\n render(date);\n }\n });\n } else {\n if (interval) {\n clearInterval(interval);\n interval = undefined;\n }\n }\n });\n\n intersectionObserver.observe(el);\n\n effect(() => {\n evaluateDate((date) => {\n if (interval) {\n clearInterval(interval);\n }\n\n render(date);\n\n setupInterval(date);\n });\n });\n\n cleanup(() => clearInterval(interval));\n }\n );\n\n Alpine.magic(\"timeago\", () => (expression, pure, seconds, strictOptions) => {\n if (pure == null) {\n pure = false;\n }\n if (seconds == null) {\n seconds = false;\n }\n if (strictOptions != null && (strictOptions[\"strict\"] || undefined)) {\n return formatDistanceToNowStrict(expression, {\n addSuffix: !pure,\n unit: strictOptions[\"unit\"] || undefined,\n roundingMethod: strictOptions[\"roundingMethod\"] || undefined,\n locale,\n });\n }\n return formatDistanceToNow(expression, {\n addSuffix: !pure,\n includeSeconds: seconds,\n locale,\n });\n });\n}\n\nTimeAgo.configure = (config) => {\n if (config.hasOwnProperty(\"locale\") && typeof config.locale === \"object\") {\n if (config.locale.hasOwnProperty(\"formatDistance\")) {\n locale = config.locale;\n }\n }\n\n return TimeAgo;\n};\n\nexport default TimeAgo;\n","import TimeAgo from '../src/index.js';\n\ndocument.addEventListener('alpine:init', () => {\n TimeAgo(window.Alpine);\n});\n"],"names":["requiredArgs","required","args","length","TypeError","toDate","argument","arguments","argStr","Object","prototype","toString","call","Date","getTime","console","warn","Error","stack","NaN","compareAsc","dirtyDateLeft","dirtyDateRight","dateLeft","dateRight","diff","differenceInCalendarMonths","yearDiff","getFullYear","monthDiff","getMonth","endOfDay","dirtyDate","date","setHours","endOfMonth","month","setFullYear","isLastDayOfMonth","differenceInMonths","result","sign","difference","Math","abs","getDate","setDate","setMonth","isLastMonthNotFull","Number","differenceInMilliseconds","roundingMap","ceil","round","floor","trunc","value","getRoundingMethod","method","differenceInSeconds","options","roundingMethod","formatDistanceLocale","lessThanXSeconds","one","other","xSeconds","halfAMinute","lessThanXMinutes","xMinutes","aboutXHours","xHours","xDays","aboutXWeeks","xWeeks","aboutXMonths","xMonths","aboutXYears","xYears","overXYears","almostXYears","formatDistance$2","token","count","tokenValue","replace","addSuffix","comparison","buildFormatLongFn","undefined","width","String","defaultWidth","format","formats","formatLong$1","full","long","medium","short","time","dateTime","formatRelativeLocale","lastWeek","yesterday","today","tomorrow","nextWeek","formatRelative$1","_date","_baseDate","_options","buildLocalizeFn","dirtyIndex","dirtyOptions","valuesArray","context","formattingValues","defaultFormattingWidth","_defaultWidth","_width","values","argumentCallback","localize$1","ordinalNumber","dirtyNumber","number","rem100","era","narrow","abbreviated","wide","quarter","day","dayPeriod","am","pm","midnight","noon","morning","afternoon","evening","night","buildMatchFn","string","matchPattern","matchPatterns","defaultMatchWidth","matchResult","match","matchedString","parsePatterns","defaultParseWidth","key","Array","isArray","findIndex","pattern","test","findKey","valueCallback","rest","slice","object","predicate","hasOwnProperty","array","parsePattern","parseInt","parseResult","any","index","defaultLocale","code","formatDistance","formatLong","formatRelative","localize","weekStartsOn","firstWeekContainsDate","cloneObject","dirtyObject","target","property","assign","getTimezoneOffsetInMilliseconds","utcDate","UTC","getHours","getMinutes","getSeconds","getMilliseconds","setUTCFullYear","MINUTES_IN_DAY","MINUTES_IN_MONTH","dirtyBaseDate","locale","RangeError","isNaN","localizeOptions","Boolean","months","seconds","offsetInSeconds","minutes","includeSeconds","hours","days","nearestMonth","monthsSinceStartOfYear","years","formatDistanceToNow","distanceInWords","now","MILLISECONDS_IN_MINUTE","MINUTES_IN_YEAR","formatDistanceStrict","roundingMethodFn","unit","milliseconds","timezoneOffset","dstNormalizedMinutes","roundedMinutes","formatDistanceToNowStrict","millisecondsInHour","toInteger","patterns","dateTimeDelimiter","timeZoneDelimiter","timezone","dateRegex","timeRegex","timezoneRegex","splitDateString","dateString","timeString","dateStrings","split","substr","exec","parseYear","additionalDigits","regex","RegExp","captures","year","restDateString","century","parseDate","isWeekDate","dayOfYear","parseDateUnit","week","dayOfWeek","_year","validateWeekDate","isoWeekYear","fourthOfJanuaryDay","getUTCDay","setUTCDate","getUTCDate","dayOfISOWeekYear","daysInMonths","isLeapYearIndex","validateDate","validateDayOfYearDate","max","parseTime","parseTimeUnit","validateTime","parseFloat","parseTimezone","timezoneString","_hours","validateTimezone","isPast","TimeAgo","Alpine","directive","el","expression","modifiers","evaluateLater","effect","cleanup","evaluateDate","render","parseYearResult","offset","timestamp","getUTCFullYear","getUTCMonth","getUTCHours","getUTCMinutes","getUTCSeconds","getUTCMilliseconds","parseISO","includes","modifier","textContent","dispatch","e","error","interval","dispatchEvent","CustomEvent","detail","bubbles","setupInterval","intervalDuration","setInterval","IntersectionObserver","entries","entry","isIntersecting","clearInterval","observe","magic","pure","strictOptions","configure","config","document","addEventListener","window"],"mappings":"2FAAe,SAASA,EAAaC,EAAUC,GAC7C,GAAIA,EAAKC,OAASF,EAChB,MAAM,IAAIG,UAAUH,EAAW,aAAeA,EAAW,EAAI,IAAM,IAAM,uBAAyBC,EAAKC,OAAS,WAEpH,CC4Be,SAASE,EAAOC,GAC7BN,EA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AAW,IAAM,CAACrC,EAAYsC,EAAMpH,EAASqH,KAC5C,MAARD,IACFA,GAAO,GAEM,MAAXpH,IACFA,GAAU,GAES,MAAjBqH,GAA0BA,EAAa,OAClChG,EAA0ByD,EAAY,CAC3ClM,WAAYwO,EACZpG,KAAMqG,EAAa,WAAYtO,EAC/B5B,eAAgBkQ,EAAa,qBAAsBtO,EACnD2G,YAGGe,EAAoBqE,EAAY,CACrClM,WAAYwO,EACZjH,eAAgBH,EAChBN,cAGL,CAEDgF,GAAQ4C,UAAaC,IACfA,EAAO5J,eAAe,WAAsC,iBAAlB4J,EAAO7H,QAC/C6H,EAAO7H,OAAO/B,eAAe,oBAC/B+B,GAAS6H,EAAO7H,QAIbgF,IC7IT8C,SAASC,iBAAiB,eAAe,KACrC/C,GAAQgD,OAAO/C,OAAf"} -------------------------------------------------------------------------------- /examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | Alpine Timeago Examples 9 | 10 | 11 | 12 | 13 | 14 |

Default

15 |
16 |

Pure

17 |
18 |

With seconds

19 |
20 |

With pure seconds

21 |
22 |

Strict

23 |
24 |

Strict unit (seconds)

25 |
26 |

Strict unit (minutes)

27 |
28 |

Strict unit (hours)

29 |
30 |

Strict unit (days)

31 |
32 |

Strict unit (months)

33 |
34 |

Strict unit (years)

35 |
36 |

Strict roundingMethod (floor)

37 |
38 |

Strict roundingMethod (ceil)

39 |
40 |

Strict roundingMethod (round)

41 |
42 |

Magic

43 |
44 |

Magic (pure)

45 |
46 |

Magic (seconds)

47 |
48 |

Magic (pure seconds)

49 |
50 |

Magic (strict)

51 |
52 | 53 | 54 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@marcreichel/alpine-timeago", 3 | "version": "0.0.0", 4 | "description": "Display the time difference between now and a given date in a human readable format", 5 | "license": "MIT", 6 | "author": { 7 | "name": "Marc Reichel", 8 | "url": "https://marcreichel.dev/" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/marcreichel/alpine-timeago.git" 13 | }, 14 | "main": "src/index.js", 15 | "scripts": { 16 | "build": "rollup -c", 17 | "watch": "rollup -c -w" 18 | }, 19 | "bugs": { 20 | "url": "https://github.com/marcreichel/alpine-timeago/issues" 21 | }, 22 | "homepage": "https://github.com/marcreichel/alpine-timeago#readme", 23 | "dependencies": { 24 | "date-fns": "^2.14.0" 25 | }, 26 | "devDependencies": { 27 | "@babel/core": "^7.17.8", 28 | "@babel/preset-env": "^7.16.11", 29 | "rollup": "^2.67.2", 30 | "rollup-plugin-babel": "^4.4.0", 31 | "rollup-plugin-filesize": "^9.1.2", 32 | "rollup-plugin-node-resolve": "^5.2.0", 33 | "rollup-plugin-terser": "^7.0.2" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import babel from 'rollup-plugin-babel'; 2 | import filesize from 'rollup-plugin-filesize'; 3 | import resolve from 'rollup-plugin-node-resolve'; 4 | import { terser } from 'rollup-plugin-terser'; 5 | 6 | export default { 7 | input: 'builds/cdn.js', 8 | output: [ 9 | { 10 | file: 'dist/alpine-timeago.js', 11 | format: 'umd', 12 | sourcemap: true, 13 | }, 14 | { 15 | file: 'dist/alpine-timeago.min.js', 16 | format: 'umd', 17 | plugins: [terser()], 18 | sourcemap: true, 19 | }, 20 | ], 21 | plugins: [ 22 | resolve(), 23 | filesize(), 24 | babel({ 25 | babelrc: false, 26 | exclude: 'node_modules/**', 27 | presets: [ 28 | [ 29 | '@babel/preset-env', 30 | { 31 | targets: { 32 | node: 'current', 33 | }, 34 | }, 35 | ], 36 | ], 37 | }), 38 | ], 39 | }; 40 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import formatDistanceToNow from "date-fns/formatDistanceToNow"; 2 | import formatDistanceToNowStrict from "date-fns/formatDistanceToNowStrict"; 3 | import parseISO from "date-fns/parseISO"; 4 | import isPast from "date-fns/isPast"; 5 | 6 | let locale = null; 7 | 8 | function TimeAgo(Alpine) { 9 | Alpine.directive( 10 | "timeago", 11 | (el, { expression, modifiers }, { evaluateLater, effect, cleanup }) => { 12 | let evaluateDate = evaluateLater(expression); 13 | 14 | const render = (date) => { 15 | if (typeof date === "string") { 16 | date = parseISO(date); 17 | } 18 | 19 | try { 20 | if (modifiers.includes("strict")) { 21 | let unit = modifiers.includes("unit") 22 | ? modifiers[ 23 | modifiers.findIndex((modifier) => modifier === "unit") + 1 24 | ] || undefined 25 | : undefined; 26 | if ( 27 | !["second", "minute", "hour", "day", "month", "year"].includes( 28 | unit 29 | ) 30 | ) { 31 | unit = undefined; 32 | } 33 | let roundingMethod = modifiers.includes("rounding") 34 | ? modifiers[ 35 | modifiers.findIndex((modifier) => modifier === "rounding") + 1 36 | ] || undefined 37 | : undefined; 38 | if (!["floor", "ceil", "round"].includes(roundingMethod)) { 39 | roundingMethod = undefined; 40 | } 41 | el.textContent = formatDistanceToNowStrict(date, { 42 | addSuffix: !modifiers.includes("pure"), 43 | unit, 44 | roundingMethod, 45 | locale, 46 | }); 47 | } else { 48 | el.textContent = formatDistanceToNow(date, { 49 | addSuffix: !modifiers.includes("pure"), 50 | includeSeconds: modifiers.includes("seconds"), 51 | locale, 52 | }); 53 | } 54 | 55 | dispatch(date); 56 | } catch (e) { 57 | console.error(e); 58 | } 59 | }; 60 | 61 | let interval; 62 | 63 | const dispatch = (date) => { 64 | el.dispatchEvent(new CustomEvent("timeago:render", { detail: { isPast: isPast(date) }, bubbles: false })); 65 | }; 66 | 67 | const setupInterval = (date) => { 68 | let intervalDuration = 30000; 69 | if (modifiers.includes("seconds")) { 70 | intervalDuration = 5000; 71 | } 72 | 73 | interval = setInterval(() => { 74 | render(date); 75 | }, intervalDuration); 76 | }; 77 | 78 | const intersectionObserver = new IntersectionObserver((entries) => { 79 | const [entry] = entries; 80 | const {isIntersecting} = entry; 81 | if (isIntersecting) { 82 | evaluateDate((date) => { 83 | if (!interval) { 84 | setupInterval(date); 85 | render(date); 86 | } 87 | }); 88 | } else { 89 | if (interval) { 90 | clearInterval(interval); 91 | interval = undefined; 92 | } 93 | } 94 | }); 95 | 96 | intersectionObserver.observe(el); 97 | 98 | effect(() => { 99 | evaluateDate((date) => { 100 | if (interval) { 101 | clearInterval(interval); 102 | } 103 | 104 | render(date); 105 | 106 | setupInterval(date); 107 | }); 108 | }); 109 | 110 | cleanup(() => clearInterval(interval)); 111 | } 112 | ); 113 | 114 | Alpine.magic("timeago", () => (expression, pure, seconds, strictOptions) => { 115 | if (pure == null) { 116 | pure = false; 117 | } 118 | if (seconds == null) { 119 | seconds = false; 120 | } 121 | if (strictOptions != null && (strictOptions["strict"] || undefined)) { 122 | return formatDistanceToNowStrict(expression, { 123 | addSuffix: !pure, 124 | unit: strictOptions["unit"] || undefined, 125 | roundingMethod: strictOptions["roundingMethod"] || undefined, 126 | locale, 127 | }); 128 | } 129 | return formatDistanceToNow(expression, { 130 | addSuffix: !pure, 131 | includeSeconds: seconds, 132 | locale, 133 | }); 134 | }); 135 | } 136 | 137 | TimeAgo.configure = (config) => { 138 | if (config.hasOwnProperty("locale") && typeof config.locale === "object") { 139 | if (config.locale.hasOwnProperty("formatDistance")) { 140 | locale = config.locale; 141 | } 142 | } 143 | 144 | return TimeAgo; 145 | }; 146 | 147 | export default TimeAgo; 148 | --------------------------------------------------------------------------------