├── .babelrc ├── .browserslistrc ├── .editorconfig ├── .eslintrc.js ├── .github └── workflows │ └── test.yml ├── .gitignore ├── .nycrc ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── bower.json ├── dist ├── fecha.min.js └── fecha.min.js.map ├── lib ├── fecha.d.ts ├── fecha.js ├── fecha.js.map ├── fecha.umd.js └── fecha.umd.js.map ├── package-lock.json ├── package.json ├── rollup.config.js ├── src └── fecha.ts ├── test.js ├── tsconfig.json └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "@babel/preset-env" 5 | ] 6 | ], 7 | "plugins": ["@babel/plugin-proposal-optional-chaining"] 8 | } -------------------------------------------------------------------------------- /.browserslistrc: -------------------------------------------------------------------------------- 1 | defaults -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | # Unix-style newlines with a newline ending every file 5 | [*] 6 | end_of_line = lf 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 2 10 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parser: '@typescript-eslint/parser', 4 | plugins: [ 5 | '@typescript-eslint', 6 | ], 7 | extends: [ 8 | 'eslint:recommended', 9 | 'plugin:@typescript-eslint/eslint-recommended', 10 | 'plugin:@typescript-eslint/recommended', 11 | 'prettier', 12 | ], 13 | rules: { 14 | "@typescript-eslint/ban-ts-ignore": "off" 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | node-version: [12.x, 14.x, 16.x] 20 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 21 | 22 | steps: 23 | - uses: actions/checkout@v3 24 | - name: Use Node.js ${{ matrix.node-version }} 25 | uses: actions/setup-node@v3 26 | with: 27 | node-version: ${{ matrix.node-version }} 28 | cache: 'npm' 29 | - run: npm ci 30 | - run: npm run build --if-present 31 | - run: npm test 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | .nyc_output 4 | ts-out -------------------------------------------------------------------------------- /.nycrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@istanbuljs/nyc-config-typescript" 3 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 12.14 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### 4.2.3 2 | - Fixed bug with UTC date on daylights savings time #94 3 | 4 | ### 4.2.1 5 | - Fixed missing source map 6 | - Fixed security y18n 7 | 8 | ### 4.2.0 9 | Added isoDate and isoDateTime masks 10 | 11 | ### 4.1.0 12 | Added Z format/parse and fixed Peru timezone issue 13 | - Added `Z` format token. See readme for more info. Big thanks to @fer22f for writing the code. 14 | - Fixed a strange issue when Peru changed timezones in 1990. See #78 15 | 16 | ## 4.0.0 17 | **Major Features and Breaking changes in this version** 18 | 19 | #### Improvements 20 | - *Valid date parsing* - By default fecha will check validity of dates. Previously `2019-55-01` or `2019-01-42` would parse correctly, since Javascript can handle it. Now invalid dates will return `null` instead 21 | - *ES Module and Tree Shaking Support* - You can now import fecha `parse` or `format` independently 22 | ```js 23 | import {format, parse} from 'fecha'; 24 | 25 | format(...); 26 | parse(...) 27 | ``` 28 | 29 | #### Breaking changes 30 | - `parseDate` may return `null` when previously returned a `Date`. See improvements above, but invalid dates will return `null` now 31 | - Change to how to set masks and i18n 32 | Previously 33 | ```js 34 | import fecha from 'fecha'; 35 | 36 | fecha.i18n = { ... } 37 | fecha.masks.myMask = 'DD , MM, YYYY' 38 | ``` 39 | 40 | New 41 | ```js 42 | import {parse, format, setGlobalDateI18n, setGlobalDateMasks} from 'fecha'; 43 | 44 | setGlobalDateI18n({ 45 | // ... 46 | }) 47 | setGlobalDateMasks({ 48 | myMask: 'DD , MM, YYYY' 49 | }); 50 | ``` 51 | 52 | ### 3.0.3 53 | - Fixed bug when using brackets when parsing dates 54 | ### 3.0.2 55 | - Fixed issue where src files are not included correctly in npm 56 | 57 | ### 3.0.0 58 | - Moved to ES modules 59 | - Changed invalid date from `false` to `null` 60 | 61 | ### 2.3.3 62 | Fixed bug with year 999 not having leading zero 63 | 64 | ### 2.3.2 65 | Added typescript definitions to NPM 66 | 67 | ### 2.3.0 68 | Added strict version of date parser that returns null on invalid dates (may use strict version in v3) 69 | 70 | ### 2.2.0 71 | Fixed a bug when parsing Do format dates 72 | 73 | ## 2.0.0 74 | Fecha now throws errors on invalid dates in `fecha.format` and is stricter about what dates it accepts. Dates must pass `Object.prototype.toString.call(dateObj) !== '[object Date]'`. 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | We are open to, and grateful for, any contributions made by the community. 3 | 4 | ## Reporting Issues and Asking Questions 5 | Before opening an issue, please search the [issue tracker](https://github.com/taylorhakes/fecha/issues) to make sure your issue hasn't already been reported. 6 | 7 | ## Development 8 | 9 | Visit the [Issue tracker](https://github.com/taylorhakes/fecha/issues) to find a list of open issues that need attention. 10 | 11 | Fork, then clone the repo: 12 | ``` 13 | git clone https://github.com/your-username/fecha.git 14 | ``` 15 | 16 | ### New Features 17 | 18 | Please open an issue with a proposal for a new feature or refactoring before starting on the work. We don't want you to waste your efforts on a pull request that we won't want to accept. 19 | 20 | ## Submitting Changes 21 | 22 | * Open a new issue in the [Issue tracker](https://github.com/taylorhakes/fecha/issues). 23 | * Fork the repo. 24 | * Create a new feature branch based off the `master` branch. 25 | * Make sure all tests pass and there are no linting errors. 26 | * Submit a pull request, referencing any issues it addresses. 27 | 28 | Please try to keep your pull request focused in scope and avoid including unrelated commits. 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Taylor Hakes 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fecha [](https://travis-ci.org/taylorhakes/fecha) 2 | 3 | Lightweight date formatting and parsing (~2KB). Meant to replace parsing and formatting functionality of moment.js. 4 | 5 | ### NPM 6 | ``` 7 | npm install fecha --save 8 | ``` 9 | ### Yarn 10 | ``` 11 | yarn add fecha 12 | ``` 13 | 14 | ### Fecha vs Moment 15 |
19 | | Fecha | 20 |Moment | 21 |
---|---|---|
Size (Min. and Gzipped) | 24 |2.1KBs | 25 |13.1KBs | 26 |
Date Parsing | 29 |✓ | 30 |✓ | 31 |
Date Formatting | 34 |✓ | 35 |✓ | 36 |
Date Manipulation | 39 |40 | | ✓ | 41 |
I18n Support | 44 |✓ | 45 |✓ | 46 |
177 | | Token | 178 |Output | 179 |
---|---|---|
Month | 182 |M | 183 |1 2 ... 11 12 | 184 |
187 | | MM | 188 |01 02 ... 11 12 | 189 |
192 | | MMM | 193 |Jan Feb ... Nov Dec | 194 |
197 | | MMMM | 198 |January February ... November December | 199 |
Day of Month | 202 |D | 203 |1 2 ... 30 31 | 204 |
207 | | Do | 208 |1st 2nd ... 30th 31st | 209 |
212 | | DD | 213 |01 02 ... 30 31 | 214 |
Day of Week | 217 |d | 218 |0 1 ... 5 6 | 219 |
222 | | ddd | 223 |Sun Mon ... Fri Sat | 224 |
227 | | dddd | 228 |Sunday Monday ... Friday Saturday | 229 |
Year | 232 |YY | 233 |70 71 ... 29 30 | 234 |
237 | | YYYY | 238 |1970 1971 ... 2029 2030 | 239 |
AM/PM | 242 |A | 243 |AM PM | 244 |
247 | | a | 248 |am pm | 249 |
Hour | 252 |H | 253 |0 1 ... 22 23 | 254 |
257 | | HH | 258 |00 01 ... 22 23 | 259 |
262 | | h | 263 |1 2 ... 11 12 | 264 |
267 | | hh | 268 |01 02 ... 11 12 | 269 |
Minute | 272 |m | 273 |0 1 ... 58 59 | 274 |
277 | | mm | 278 |00 01 ... 58 59 | 279 |
Second | 282 |s | 283 |0 1 ... 58 59 | 284 |
287 | | ss | 288 |00 01 ... 58 59 | 289 |
Fractional Second | 292 |S | 293 |0 1 ... 8 9 | 294 |
297 | | SS | 298 |0 1 ... 98 99 | 299 |
302 | | SSS | 303 |0 1 ... 998 999 | 304 |
Timezone | 307 |Z | 308 |309 | -07:00 -06:00 ... +06:00 +07:00 310 | | 311 |
314 | | ZZ | 315 |316 | -0700 -0600 ... +0600 +0700 317 | | 318 |