├── .github └── workflows │ ├── release.yml │ └── test.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE.md ├── README.md ├── bin └── authorize-push.js ├── demo └── index.html ├── index.js ├── lib └── parseformat.js ├── package-lock.json ├── package.json └── test └── moment-parseformat-test.js /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | "on": 3 | push: 4 | branches: 5 | - master 6 | - next 7 | - beta 8 | - "*.x" 9 | jobs: 10 | release: 11 | name: release 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v3 15 | - uses: actions/setup-node@v3 16 | with: 17 | node-version: lts/* 18 | - run: npm ci 19 | - run: npm run build 20 | - run: npx semantic-release 21 | env: 22 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 23 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 24 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | "on": 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | types: 8 | - opened 9 | - synchronize 10 | jobs: 11 | test_matrix: 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | node_version: 16 | - 12 17 | - 14 18 | steps: 19 | - uses: actions/checkout@v3 20 | - name: Use Node.js ${{ matrix.node_version }} 21 | uses: actions/setup-node@v3 22 | with: 23 | node-version: ${{ matrix.node_version }} 24 | - uses: actions/cache@v2 25 | with: 26 | path: ~/.npm 27 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 28 | restore-keys: | 29 | ${{ runner.os }}-node- 30 | - run: npm ci 31 | - run: npm test 32 | test: 33 | runs-on: ubuntu-latest 34 | needs: test_matrix 35 | steps: 36 | - uses: actions/checkout@v3 37 | - run: npm ci 38 | - run: npm run test:coverage 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .coveralls.yml 2 | coverage/ 3 | demo/moment-parseformat.js 4 | dist/ 5 | node_modules/ 6 | test-builder.js 7 | 8 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at coc@martynus.net. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 Gregor Martynus 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | moment.parseFormat – a moment.js plugin 2 | ======================================= 3 | 4 | [![Test](https://github.com/gr2m/moment-parseformat/actions/workflows/test.yml/badge.svg)](https://github.com/gr2m/moment-parseformat/actions/workflows/test.yml) 5 | 6 | > A moment.js plugin to extract the format of a date/time string 7 | 8 | Installation 9 | ------------ 10 | 11 | Load via script tag 12 | 13 | ```html 14 | 15 | 16 | ``` 17 | 18 | Install using [npm](https://npmjs.org/) for node.js: 19 | 20 | ``` 21 | npm install --save moment-parseformat 22 | ``` 23 | 24 | 25 | Browser Usage 26 | ----- 27 | 28 | ```js 29 | var format = moment.parseFormat('Thursday, February 6th, 2014 9:20pm'/* , options */); 30 | // dddd, MMMM Do, YYYY h:mma 31 | moment().format(format); // format 32 | ``` 33 | 34 | 35 | Node / CommonJS Usage 36 | ----- 37 | ```js 38 | var moment = require 'moment' 39 | var parseFormat = require('moment-parseformat') 40 | 41 | var format = parseFormat('Thursday, February 6th, 2014 9:20pm'/* , options */); 42 | // dddd, MMMM Do, YYYY h:mma 43 | moment().format(format); // format 44 | ``` 45 | 46 | 47 | Options 48 | ---- 49 | 50 | Options can be passed as 2nd parameter 51 | 52 | 53 | #### preferredOrder 54 | Type: `Object` or `String` 55 | 56 | `parseFormat` tries to figure out the the order of day/month/year by itself 57 | if it finds 3 numbers separated by `.`, `-` or `/`. But if it can't, it will fallback 58 | to `preferredOrder`, which can either be set as an object to differentiate by separator, 59 | or as a simple string. 60 | 61 | Default value: 62 | 63 | ```js 64 | preferredOrder: { 65 | '/': 'MDY', 66 | '.': 'DMY', 67 | '-': 'YMD' 68 | } 69 | ``` 70 | 71 | Usage 72 | 73 | ```js 74 | parseFormat('10.10.2010', {preferredOrder: 'DMY'}); 75 | // ☛ DD.MM.YYYY 76 | parseFormat('10.10.2010', {preferredOrder: 'MDY'}); 77 | // ☛ MM.DD.YYYY 78 | parseFormat('10.10.2010', {preferredOrder: { 79 | '/': 'MDY', 80 | '.': 'DMY', 81 | '-': 'YMD' 82 | }}); 83 | // ☛ MM.DD.YYYY 84 | parseFormat('10/10/2010', {preferredOrder: { 85 | '/': 'MDY', 86 | '.': 'DMY', 87 | '-': 'YMD' 88 | }}); 89 | // ☛ DD/MM/YYYY 90 | ``` 91 | 92 | 93 | Fine Print 94 | ---------- 95 | 96 | The moment.parseFormat Plugin have been authored by [Gregor Martynus](https://github.com/gr2m), 97 | proud member of the [Hoodie Community](http://hood.ie/). 98 | 99 | License: MIT 100 | -------------------------------------------------------------------------------- /bin/authorize-push.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var exec = require('child_process').exec 4 | 5 | var GH_TOKEN = process.env.GH_TOKEN 6 | var repo = require('../package.json').repository.url 7 | 8 | if (!(process.env.CI && GH_TOKEN && repo)) { 9 | console.log('[authorize-push] ignodered because condition not fullfillled (process.env.CI: %s, GH_TOKEN: %s, repo: %s)', !!process.env.CI, !!GH_TOKEN, !!repo) 10 | process.exit(1) 11 | } 12 | 13 | var commands = [ 14 | 'git remote set-url origin ' + repo.replace('https://', 'https://' + GH_TOKEN + '@'), 15 | 'git config user.email "gregor@martynus.net"', 16 | 'git config user.name "gr2m"' 17 | ] 18 | commands.forEach(function (command) { 19 | console.log('[authorize-push] %s', command.replace(GH_TOKEN, '***GH_TOKEN***')) 20 | exec(command) 21 | }) 22 | -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | moment.parseFormat – a moment.js plugin 6 | 7 | 8 | 9 | 29 | 30 | 31 | 32 |
33 |

moment.parseFormat

34 |
Made by the Hoodie Community.
35 |
36 | 37 |
38 |

The what? And the why?

39 |

40 | moment.parseFormat is a plugin for moment.js, that turns Date/Time Strings 41 | into their representing formats. 42 |

43 |

44 | That allows for date/time inputs that not only to set a date/time, but also to configure 45 | the user's preffered format. Because users hate configuration forms™, try to avoid them if you can. 46 |

47 |

48 | Here are some examples. Play with them or add new ones. If you find a problem, please report 49 |

50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 64 | 67 | 70 | 73 | 74 | 75 |
TestFormatCheckFound a bug?
62 | 63 | 65 | 66 | 68 | 69 | 71 | report 72 |
76 | 77 |

78 | Note: This demo is using the Bootstrap Editable Table 79 | plugin for auto-adding of new rows, and for styling. 80 |

81 |
82 | 83 | 84 | 85 | 86 | 87 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var parseFormat = require('./lib/parseformat') 2 | module.exports = parseFormat 3 | 4 | /* istanbul ignore next */ 5 | if (typeof window !== 'undefined' && window.moment) { 6 | window.moment.parseFormat = parseFormat 7 | } 8 | -------------------------------------------------------------------------------- /lib/parseformat.js: -------------------------------------------------------------------------------- 1 | module.exports = parseFormat 2 | 3 | var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] 4 | var abbreviatedDayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] 5 | var shortestDayNames = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'] 6 | var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] 7 | var timezoneNames = ['ACDT', 'ACST', 'ACWT', 'ADT', 'ACT', 'AEDT', 'AEST', 'AFT', 'AKDT', 'AKST', 'ALMT', 'AMT', 'AMST', 'ANAT', 'ANAST', 'AQTT', 'ART', 'AST', 'AWDT', 'AWST', 'AZOT', 'AZOST', 'AZT', 'AZST', 'BNT', 'BDT', 'BOT', 'BRT', 'BRST', 'BST', 'BTT', 'B', 'CAST', 'CAT', 'CCT', 'CDT', 'CEDT', 'CEST', 'CET', 'CHADT', 'CHAST', 'CHOT', 'CHOST', 'CHsT', 'CHUT', 'CIT', 'CKT', 'CLST', 'CLT', 'COT', 'CST', 'CVT', 'CWST', 'CXT', 'C', 'DAVT', 'DDUT', 'DST', 'EASST', 'EAST', 'EAT', 'ECT', 'EDT', 'EEDT', 'EEST', 'EET', 'EGT', 'EGST', 'EST', 'E', 'EIT', 'FET', 'FJT', 'FJST', 'FKST', 'FKT', 'FNT', 'F', 'GALT', 'GAMT', 'GET', 'GFT', 'GILT', 'GMT', 'GST', 'GYT', 'G', 'HADT', 'HAST', 'HKT', 'HOVT', 'HOVST', 'HST', 'ICT', 'IDT', 'IOT', 'IRDT', 'IRKT', 'IRKST', 'IRST', 'IST', 'JST', 'KGT', 'KOST', 'KRAT', 'KRAST', 'KST', 'KUYT', 'LHDT', 'LHST', 'LINT', 'L', 'MAGT', 'MAGST', 'MART', 'MAWT', 'MDT', 'MeST', 'MHT', 'MIST', 'MMT', 'MSD', 'MSK', 'MST', 'MUT', 'MVT', 'MYT', 'NCT', 'NDT', 'NFT', 'N', 'NOVT', 'NOVST', 'NPT', 'NRT', 'NST', 'NT', 'NUT', 'NZDT', 'NZST', 'OMST', 'OMSST', 'ORAT', 'O', 'PDT', 'PET', 'PETT', 'PETST', 'PGT', 'PHT', 'PHOT', 'PKT', 'PMDT', 'PMST', 'PONT', 'PST', 'PWT', 'PYT', 'PYST', 'P', 'QYZT', 'RET', 'ROTT', 'R', 'SAKT', 'SAMT', 'SAST', 'SBT', 'SCT', 'SGT', 'SRT', 'SLT', 'SLST', 'SRET', 'SST', 'SYOT', 'TAHT', 'TFT', 'TJT', 'TKT', 'TLT', 'TMT', 'TOT', 'TRUT', 'TVT', 'T', 'ULAT', 'ULAST', 'UTC', 'UYST', 'UYT', 'UZT', 'U', 'VET', 'VLAT', 'VLAST', 'VOLT', 'VUT', 'V', 'WAKT', 'WAT', 'WAST', 'WDT', 'WEDT', 'WEST', 'WET', 'WFT', 'WGT', 'WGST', 'WIB', 'WIT', 'WITA', 'WST', 'WT', 'YAKT', 'YAKST', 'YAP', 'YEK', 'YEKS'] 8 | 9 | var abbreviatedMonthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] 10 | var regexDayNames = new RegExp(dayNames.join('|'), 'i') 11 | var regexAbbreviatedDayNames = new RegExp(abbreviatedDayNames.join('|'), 'i') 12 | var regexShortestDayNames = new RegExp('\\b(' + shortestDayNames.join('|') + ')\\b', 'i') 13 | var regexMonthNames = new RegExp(monthNames.join('|'), 'i') 14 | var regexAbbreviatedMonthNames = new RegExp(abbreviatedMonthNames.join('|'), 'i') 15 | var regexTimezoneNames = new RegExp('\\b(' + timezoneNames.join('|') + ')\\b', 'i') 16 | 17 | var regexFirstSecondThirdFourth = /(\d+)(st|nd|rd|th)\b/i 18 | var regexEndian = /(\d{1,4})([/.-])(\d{1,2})[/.-](\d{1,4})/ 19 | 20 | var regexTimezone = /((\+|-)(12:00|11:00|10:00|09:30|09:00|08:00|07:00|06:00|05:00|04:00|03:30|03:00|02:00|01:00|00:00|01:00|02:00|03:00|03:30|04:00|04:30|05:00|05:30|05:45|06:00|06:30|07:00|08:00|08:45|09:00|09:30|10:00|10:30|11:00|12:00|12:45|13:00|14:00))$/ 21 | var regexTimezoneNaked = /((\+|-)(1200|1100|1000|0930|0900|0800|0700|0600|0500|0400|0330|0300|0200|0100|0000|0100|0200|0300|0330|0400|0430|0500|0530|0545|0600|0630|0700|0800|0845|0900|0930|1000|1030|1100|1200|1245|1300|1400))$/ 22 | 23 | var amOrPm = '(' + ['AM?', 'PM?'].join('|') + ')' 24 | var regexHoursWithLeadingZeroDigitMinutesSecondsAmPm = new RegExp('0\\d\\:\\d{1,2}\\:\\d{1,2}(\\s*)' + amOrPm, 'i') 25 | var regexHoursWithLeadingZeroDigitMinutesAmPm = new RegExp('0\\d\\:\\d{1,2}(\\s*)' + amOrPm, 'i') 26 | var regexHoursWithLeadingZeroDigitAmPm = new RegExp('0\\d(\\s*)' + amOrPm, 'i') 27 | var regexHoursMinutesSecondsAmPm = new RegExp('\\d{1,2}\\:\\d{1,2}\\:\\d{1,2}(\\s*)' + amOrPm, 'i') 28 | var regexHoursMinutesAmPm = new RegExp('\\d{1,2}\\:\\d{1,2}(\\s*)' + amOrPm, 'i') 29 | var regexHoursAmPm = new RegExp('\\d{1,2}(\\s*)' + amOrPm, 'i') 30 | var regexHours = /\d{1,2}/ 31 | var regexMonthNameYearShort = new RegExp(monthNames.join('|') + '-\\d{2}', 'i') 32 | var regexMonthNameAbbreviatedYearShort = new RegExp(abbreviatedMonthNames.join('|') + '-\\d{2}', 'i') 33 | 34 | // Various forms of (D|DD)(MMM|MMMM)('?YY|YYYY) 35 | var regexDayMonthNameYear = new RegExp('(\\d{1,2})(\\D+)(' + monthNames.join('|') + '|' + abbreviatedMonthNames.join('|') + ')(\\2)(\'?\\d{2,4})') 36 | 37 | var regexISO8601HoursWithLeadingZeroMinutesSecondsMilliseconds = /\d{2}:\d{2}:\d{2}\.\d{3}/ 38 | var regexISO8601HoursWithLeadingZeroMinutesSecondsCentiSeconds = /\d{2}:\d{2}:\d{2}\.\d{2}/ 39 | var regexISO8601HoursWithLeadingZeroMinutesSecondsDeciSeconds = /\d{2}:\d{2}:\d{2}\.\d{1}/ 40 | var regexISO8601HoursWithLeadingZeroMinutesSeconds = /T\d{2}:\d{2}:\d{2}/ // Weird test case - format don't usually come like this, but one of ours does. 41 | var regexHoursWithLeadingZeroMinutesSeconds = /0\d:\d{2}:\d{2}/ 42 | var regexHoursWithLeadingZeroMinutes = /0\d:\d{2}/ 43 | 44 | var regexHoursMinutesSeconds = /\b([01]?[0-9]|2[0-3]):[0-5][0-9]:\d{2}/ 45 | var regexHoursMinutesSecondsMilliseconds = /\b([01]?[0-9]|2[0-3]):[0-5][0-9]:\d{2}\.\d{3}/ 46 | var regexHoursMinutesSecondsCentiSeconds = /\b([01]?[0-9]|2[0-3]):[0-5][0-9]:\d{2}\.\d{2}/ 47 | var regexHoursMinutesSecondsDeciSeconds = /\b([01]?[0-9]|2[0-3]):[0-5][0-9]:\d{2}\.\d{1}/ 48 | var regexHoursMinutes = /\b([01]?[0-9]|2[0-3]):[0-5][0-9]/ 49 | 50 | var regexExtended24HoursMinutesSeconds = /24:00:\d{2}/ 51 | var regexExtended24HoursMinutesSecondsMilliseconds = /24:00:\d{2}\.\d{3}/ 52 | var regexExtended24HoursMinutesSecondsCentiSeconds = /24:00:\d{2}\.\d{2}/ 53 | var regexExtended24HoursMinutesSecondsDeciSeconds = /24:00:\d{2}\.\d{1}/ 54 | var regexExtended24HoursMinutes = /24:00/ 55 | 56 | var regexYearLong = /\d{4}/ 57 | var regexYearShort = /\d{2}/ 58 | var regexYearShortApostrophe = /'\d{2}/ 59 | var regexDayLeadingZero = /0\d/ 60 | var regexDay = /\d{1,2}/ 61 | 62 | var regexMonthLeadingZero = /0\d/ 63 | var regexMonth = /\d{1,2}/ 64 | 65 | var regexDayShortMonthShort = /^([1-9])\/([1-9]|0[1-9])$/ 66 | var regexDayShortMonth = /^([1-9])\/(1[012])$/ 67 | var regexDayMonthShort = /^(0[1-9]|[12][0-9]|3[01])\/([1-9])$/ 68 | var regexDayMonth = /^(0[1-9]|[12][0-9]|3[01])\/(1[012]|0[1-9])$/ 69 | 70 | var regexMonthShortYearShort = /^([1-9])(\D)([1-9][0-9])$/ 71 | var regexMonthShortDay = /^([1-9])(\D)([0][0-9])$/ 72 | var regexMonthYearShort = /^(0[1-9]|1[012])(\D)([1-9][0-9])$/ 73 | var regexMonthDay = /^(0[1-9]|1[012])(\D)([0][0-9])$/ 74 | 75 | var formatIncludesMonth = /([/][M]|[M][/]|[MM]|[MMMM])/ 76 | var formatIncludesNumericDay = /(D)/ 77 | var formatIncludesYear = /(Y)/ 78 | 79 | var formatHasMultipleRemainingSegments = /\d+\D.+$/ 80 | var formatOnlyHasTerminatingNumbers = /\D+(\d+)($|Z)/ 81 | var formatHasDayAfterMonthSegment = /M\s*\d{1,2}\b.+$/ 82 | var formatHasDayWithLeadingZeroAfterMonthSegment = /M\D+(0[1-9])\b.+$/ 83 | 84 | var formatHasTimeAfterRemainingDigits = /\d+\s+(H|h|k)/ 85 | 86 | var regexFillingWords = /\b(at)\b/i 87 | 88 | var regexUnixMillisecondTimestamp = /\d{13}/ 89 | var regexUnixTimestamp = /\d{10}/ 90 | 91 | // option defaults 92 | var defaultOrder = { 93 | '/': 'MDY', 94 | '.': 'DMY', 95 | '-': 'YMD' 96 | } 97 | 98 | function parseFormat (dateString, options) { 99 | var format = dateString.toString() 100 | 101 | // default options 102 | options = options || {} 103 | 104 | options.preferredOrder = options.preferredOrder || defaultOrder 105 | 106 | // Unix Millisecond Timestamp ☛ x 107 | format = format.replace(regexUnixMillisecondTimestamp, 'x') 108 | // Unix Timestamp ☛ X 109 | format = format.replace(regexUnixTimestamp, 'X') 110 | 111 | // escape filling words 112 | format = format.replace(regexFillingWords, '[$1]') 113 | 114 | if (format.match(regexDayMonthNameYear)) { 115 | const [, daySegment, sep1, monthSegment, sep2, yearSegment] = format.match(regexDayMonthNameYear) 116 | const parts = [] 117 | // Handle Day segment 118 | if ((daySegment.length === 2 && daySegment[0] === '0') || options.preferLongFormat) { 119 | parts.push('DD') 120 | } else { 121 | parts.push('D') 122 | } 123 | // Handle day/month seperator 124 | parts.push(sep1) 125 | // Handle Month segment 126 | if (monthSegment.match(monthNames)) { 127 | parts.push('MMMM') 128 | } else if (monthSegment.match(abbreviatedMonthNames)) { 129 | parts.push('MMM') 130 | } else { 131 | parts.push(monthSegment) 132 | } 133 | // Handle month/year seperator 134 | parts.push(sep2) 135 | // Handle year segment 136 | if (yearSegment[0] === "'") { 137 | parts.push("'YY") 138 | } else if (yearSegment.length === 2) { 139 | parts.push('YY') 140 | } else if (yearSegment.length === 4) { 141 | parts.push('YYYY') 142 | } else { 143 | parts.push('YYYY') 144 | } 145 | 146 | var dayMonthNameYearFormat = parts.join('') 147 | format = format.replace(regexDayMonthNameYear, dayMonthNameYearFormat) 148 | } 149 | 150 | // DAYS 151 | 152 | // Monday ☛ dddd 153 | format = format.replace(regexDayNames, 'dddd') 154 | // Mon ☛ ddd 155 | format = format.replace(regexAbbreviatedDayNames, 'ddd') 156 | // Mo ☛ dd 157 | format = format.replace(regexShortestDayNames, 'dd') 158 | 159 | // 1st, 2nd, 23rd ☛ do 160 | format = format.replace(regexFirstSecondThirdFourth, 'Do') 161 | 162 | // MONTHS 163 | 164 | // January ☛ MMMM 165 | format = format.replace(regexMonthNames, 'MMMM') 166 | // Jan ☛ MMM 167 | format = format.replace(regexAbbreviatedMonthNames, 'MMM') 168 | 169 | // replace endians, like 8/20/2010, 20.8.2010 or 2010-8-20 170 | format = format.replace(regexEndian, replaceEndian.bind(null, options)) 171 | 172 | // timezone name GMT ☛ [GMT] 173 | format = format.replace(regexTimezoneNames, a => '[' + a + ']') 174 | // timezone +02:00 ☛ Z 175 | format = format.replace(regexTimezone, 'Z') 176 | // timezone 0200 ☛ Z 177 | format = format.replace(regexTimezoneNaked, 'ZZ') 178 | 179 | // TIME 180 | // 23:39:43.331 ☛ 'HH:mm:ss.SSS' 181 | format = format.replace(regexISO8601HoursWithLeadingZeroMinutesSecondsMilliseconds, 'HH:mm:ss.SSS') 182 | // 23:39:43.33 ☛ 'HH:mm:ss.SS' 183 | format = format.replace(regexISO8601HoursWithLeadingZeroMinutesSecondsCentiSeconds, 'HH:mm:ss.SS') 184 | // 23:39:43.3 ☛ 'HH:mm:ss.S' 185 | format = format.replace(regexISO8601HoursWithLeadingZeroMinutesSecondsDeciSeconds, 'HH:mm:ss.S') 186 | // 23:39:43 ☛ 'HH:mm:ss' 187 | format = format.replace(regexISO8601HoursWithLeadingZeroMinutesSeconds, 'THH:mm:ss') 188 | function replaceWithAmPm (timeFormat) { 189 | return function (match, whitespace, amPm) { 190 | return timeFormat + whitespace + (amPm[0].toUpperCase() === amPm[0] ? 'A' : 'a') 191 | } 192 | } 193 | // 05:30:20pm ☛ hh:mm:ssa 194 | format = format.replace(regexHoursWithLeadingZeroDigitMinutesSecondsAmPm, replaceWithAmPm('hh:mm:ss')) 195 | // 10:30:20pm ☛ h:mm:ssa 196 | format = format.replace(regexHoursMinutesSecondsAmPm, replaceWithAmPm('h:mm:ss')) 197 | // 05:30pm ☛ hh:mma 198 | format = format.replace(regexHoursWithLeadingZeroDigitMinutesAmPm, replaceWithAmPm('hh:mm')) 199 | // 10:30pm ☛ h:mma 200 | format = format.replace(regexHoursMinutesAmPm, replaceWithAmPm('h:mm')) 201 | // 05pm ☛ hha 202 | format = format.replace(regexHoursWithLeadingZeroDigitAmPm, replaceWithAmPm('hh')) 203 | // 10pm ☛ ha 204 | format = format.replace(regexHoursAmPm, replaceWithAmPm('h')) 205 | // 05:30:20 ☛ HH:mm:ss 206 | format = format.replace(regexHoursWithLeadingZeroMinutesSeconds, 'HH:mm:ss') 207 | // 5:30:20.222 ☛ H:mm:ss.SSS 208 | format = format.replace(regexHoursMinutesSecondsMilliseconds, 'H:mm:ss.SSS') 209 | // 24:00:00.000 ☛ k:mm:ss.SSS|kk:mm:ss.SSS 210 | format = format.replace(regexExtended24HoursMinutesSecondsMilliseconds, (options.preferLongFormat ? 'kk' : 'k') + ':mm:ss.SSS') 211 | // 5:30:20.22 ☛ H:mm:ss.SS 212 | format = format.replace(regexHoursMinutesSecondsCentiSeconds, 'H:mm:ss.SS') 213 | // 24:00:00.00 ☛ k:mm:ss.SS|kk:mm:ss.SS 214 | format = format.replace(regexExtended24HoursMinutesSecondsCentiSeconds, (options.preferLongFormat ? 'kk' : 'k') + ':mm:ss.SS') 215 | // 5:30:20.2 ☛ H:mm:ss.S 216 | format = format.replace(regexHoursMinutesSecondsDeciSeconds, 'H:mm:ss.S') 217 | // 24:00:00.0 ☛ k:mm:ss.S|kk:mm:ss.S 218 | format = format.replace(regexExtended24HoursMinutesSecondsDeciSeconds, (options.preferLongFormat ? 'kk' : 'k') + ':mm:ss.S') 219 | // 10:30:20 ☛ H:mm:ss 220 | format = format.replace(regexHoursMinutesSeconds, 'H:mm:ss') 221 | // 24:00:00 ☛ k:mm:ss||kk:mm:ss 222 | format = format.replace(regexExtended24HoursMinutesSeconds, (options.preferLongFormat ? 'kk' : 'k') + ':mm:ss') 223 | // 05:30 ☛ H:mm 224 | format = format.replace(regexHoursWithLeadingZeroMinutes, 'HH:mm') 225 | // 10:30 ☛ HH:mm 226 | format = format.replace(regexHoursMinutes, 'H:mm') 227 | // 24:00 ☛ k:mm|kk:mm 228 | format = format.replace(regexExtended24HoursMinutes, (options.preferLongFormat ? 'kk' : 'k') + ':mm') 229 | 230 | // do we still have numbers left? 231 | // 232 | // 233 | 234 | // Lets check for 4 digits first, these are years for sure 235 | format = format.replace(regexYearLong, 'YYYY') 236 | format = format.replace(regexYearShortApostrophe, '\'YY') 237 | 238 | // Check for (MMM|MMMM)-(YY|YYYY) formats 239 | format = format.replace(regexMonthNameYearShort, 'MMMM-YY') 240 | format = format.replace(regexMonthNameAbbreviatedYearShort, 'MMM-YY') 241 | 242 | // check if both numbers are < 13, then it must be D/M 243 | format = format.replace(regexDayShortMonthShort, 'D/M') 244 | 245 | // check if first number is < 10 && last < 13, then it must be D/MM 246 | format = format.replace(regexDayShortMonth, 'D/MM') 247 | 248 | // check if last number is < 32 && last < 10, then it must be DD/M 249 | format = format.replace(regexDayMonthShort, 'DD/M') 250 | 251 | // check if both numbers are > 10, but first < 32 && last < 13, then it must be DD/MM 252 | format = format.replace(regexDayMonth, 'DD/MM') 253 | 254 | // check if first < 10 && last > 12, then it must be M/YY 255 | format = format.replace(regexMonthShortYearShort, 'M$2YY') 256 | 257 | // check if first < 13 && last > 12, then it must be MM/YY 258 | format = format.replace(regexMonthYearShort, 'MM$2YY') 259 | // 260 | // check if first < 10 && last < 10, then it must be M/DD 261 | format = format.replace(regexMonthShortDay, 'M$2DD') 262 | 263 | // check if first < 13 && last < 10, then it must be MM/DD 264 | format = format.replace(regexMonthDay, 'MM$2DD') 265 | 266 | // to prevent 9.20 gets formated to D.Y, we format the complete date first, then go for the time 267 | if (format.match(formatIncludesMonth)) { 268 | var regexHoursDotWithLeadingZeroOrDoubleDigitMinutes = /0\d\.\d{2}|\d{2}\.\d{2}/ 269 | var regexHoursDotMinutes = /\d{1}\.\d{2}/ 270 | 271 | format = format.replace(regexHoursDotWithLeadingZeroOrDoubleDigitMinutes, 'H.mm') 272 | format = format.replace(regexHoursDotMinutes, 'h.mm') 273 | } 274 | 275 | // If the format includes a year format segment, but no month segment, then those numbers are a month 276 | 277 | if (!format.match(formatIncludesMonth) && format.match(formatIncludesYear)) { 278 | format = format.replace(regexMonthLeadingZero, 'MM') 279 | } 280 | if (!format.match(formatIncludesMonth) && format.match(formatIncludesYear)) { 281 | format = format.replace(regexMonth, options.preferLongFormat ? 'MM' : 'M') 282 | } 283 | 284 | // Check for some odd cases, such as MMMM 285 | if (format.match(formatHasDayWithLeadingZeroAfterMonthSegment) && !format.match(formatHasTimeAfterRemainingDigits)) { 286 | format = format.replace(regexDayLeadingZero, 'DD') 287 | } 288 | if (format.match(formatHasDayAfterMonthSegment) && !format.match(formatHasTimeAfterRemainingDigits)) { 289 | format = format.replace(regexDay, options.preferLongFormat ? 'DD' : 'D') 290 | } 291 | 292 | // now, the next number, if existing, must be a day IF it is the last set of numbers in the format 293 | if (!format.match(formatIncludesNumericDay) && format.match(formatHasMultipleRemainingSegments) && !format.match(formatHasTimeAfterRemainingDigits)) { 294 | format = format.replace(regexDayLeadingZero, 'DD') 295 | } 296 | if (!format.match(formatIncludesNumericDay) && format.match(formatHasMultipleRemainingSegments) && !format.match(formatHasTimeAfterRemainingDigits)) { 297 | format = format.replace(regexDay, options.preferLongFormat ? 'DD' : 'D') 298 | } 299 | 300 | // there could still be a year left 301 | if (!format.match(formatIncludesYear)) { 302 | format = format.replace(regexYearShort, 'YY') 303 | } 304 | 305 | // if there are still numbers, it might be an odd naked hour that wasn't picked up earlier by the time checks 306 | if (format.match(formatOnlyHasTerminatingNumbers)) { 307 | var hour = format.match(formatOnlyHasTerminatingNumbers)[1] 308 | var replacement 309 | if (hour === '00') { 310 | replacement = 'HH' 311 | } else if (hour === '24') { 312 | replacement = options.preferLongFormat ? 'kk' : 'k' 313 | } else if (hour > 12) { 314 | replacement = options.preferLongFormat ? 'HH' : 'H' 315 | } else if (hour[0] === '0') { 316 | replacement = options.preferLongFormat ? 'hh' : 'h' 317 | } else { 318 | replacement = options.preferLongFormat ? 'hh' : 'k' 319 | } 320 | format = format.replace(regexHours, replacement) 321 | } 322 | 323 | if (format.length < 1) { 324 | format = undefined 325 | } 326 | 327 | return format 328 | } 329 | 330 | // if we can't find an endian based on the separator, but 331 | // there still is a short date with day, month & year, 332 | // we try to make a smart decision to identify the order 333 | function replaceEndian (options, matchedPart, first, separator, second, third) { 334 | var parts 335 | 336 | var FIRST = 0 337 | var SECOND = 1 338 | var THIRD = 2 339 | 340 | var isSingleDigitMap = [ 341 | first.length === 1, 342 | second.length === 1, 343 | third.length === 1 344 | ] 345 | 346 | var startsWithZeroMap = [ 347 | first[0] === '0', 348 | second[0] === '0', 349 | third[0] === '0' 350 | ] 351 | 352 | var firstHasQuadDigit = first.length === 4 353 | var secondHasQuadDigit = second.length === 4 354 | var thirdHasQuadDigit = third.length === 4 355 | 356 | var preferredOrder = typeof options.preferredOrder === 'string' ? options.preferredOrder : options.preferredOrder[separator] 357 | 358 | first = parseInt(first, 10) 359 | second = parseInt(second, 10) 360 | third = parseInt(third, 10) 361 | parts = [first, second, third] 362 | preferredOrder = preferredOrder.toUpperCase() 363 | 364 | var inferSingleDigitStatus = function (a, b) { 365 | if (isSingleDigitMap[a] !== isSingleDigitMap[b]) { 366 | if (!startsWithZeroMap[a] && !startsWithZeroMap[b]) { 367 | isSingleDigitMap[a] = true 368 | isSingleDigitMap[b] = true 369 | } 370 | } 371 | } 372 | 373 | // If first is a year, order will always be Year-Month-Day 374 | if (first > 31) { 375 | inferSingleDigitStatus(SECOND, THIRD) 376 | parts[0] = firstHasQuadDigit ? 'YYYY' : 'YY' 377 | parts[1] = isSingleDigitMap[SECOND] ? 'M' : 'MM' 378 | parts[2] = isSingleDigitMap[THIRD] ? 'D' : 'DD' 379 | return parts.join(separator) 380 | } 381 | 382 | // If first is a month, then the order will be Day-Month-Year 383 | if (first > 12) { 384 | inferSingleDigitStatus(FIRST, SECOND) 385 | parts[0] = isSingleDigitMap[FIRST] ? 'D' : 'DD' 386 | parts[1] = isSingleDigitMap[SECOND] ? 'M' : 'MM' 387 | parts[2] = thirdHasQuadDigit ? 'YYYY' : 'YY' 388 | return parts.join(separator) 389 | } 390 | 391 | // Second will never be the year. And if it is a day, 392 | // the order will always be Month-Day-Year 393 | if (second > 12) { 394 | inferSingleDigitStatus(FIRST, SECOND) 395 | parts[0] = isSingleDigitMap[FIRST] ? 'M' : 'MM' 396 | parts[1] = isSingleDigitMap[SECOND] ? 'D' : 'DD' 397 | parts[2] = thirdHasQuadDigit ? 'YYYY' : 'YY' 398 | return parts.join(separator) 399 | } 400 | 401 | // if third is a year ... 402 | if (third > 31) { 403 | parts[2] = thirdHasQuadDigit ? 'YYYY' : 'YY' 404 | 405 | // ... try to find day in first and second. 406 | // If found, the remaining part is the month. 407 | if (preferredOrder[0] === 'M' && first < 13) { 408 | inferSingleDigitStatus(FIRST, SECOND) 409 | parts[0] = isSingleDigitMap[FIRST] ? 'M' : 'MM' 410 | parts[1] = isSingleDigitMap[SECOND] ? 'D' : 'DD' 411 | return parts.join(separator) 412 | } 413 | 414 | inferSingleDigitStatus(FIRST, SECOND) 415 | parts[0] = isSingleDigitMap[FIRST] ? 'D' : 'DD' 416 | parts[1] = isSingleDigitMap[SECOND] ? 'M' : 'MM' 417 | return parts.join(separator) 418 | } 419 | 420 | const hasQuadDigit = [firstHasQuadDigit, secondHasQuadDigit, thirdHasQuadDigit] 421 | 422 | // if we had no luck until here, we use the preferred order 423 | inferSingleDigitStatus(preferredOrder.indexOf('D'), preferredOrder.indexOf('M')) 424 | parts[preferredOrder.indexOf('D')] = isSingleDigitMap[preferredOrder.indexOf('D')] ? 'D' : 'DD' 425 | parts[preferredOrder.indexOf('M')] = isSingleDigitMap[preferredOrder.indexOf('M')] ? 'M' : 'MM' 426 | 427 | parts[preferredOrder.indexOf('Y')] = hasQuadDigit[preferredOrder.indexOf('Y')] ? 'YYYY' : 'YY' 428 | return parts.join(separator) 429 | } 430 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "moment-parseformat", 3 | "description": "A moment.js plugin to extract the format of a date/time string", 4 | "scripts": { 5 | "start": "npm run build:demo && beefy ./index.js --cwd=./demo", 6 | "prebuild": "rimraf dist && mkdirp dist", 7 | "build": "browserify index.js -s moment-parseformat -o dist/moment-parseformat.js", 8 | "build:demo": "browserify index.js -s moment-parseformat -o demo/moment-parseformat.js", 9 | "deploy": "npm run build:demo && npm run deploydocs", 10 | "predeploydocs": "./bin/authorize-push.js", 11 | "deploydocs": "gh-pages-deploy", 12 | "pretest": "standard", 13 | "test": "npm run -s test:node | tap-spec", 14 | "test:coverage": "istanbul cover test/moment-parseformat-test.js", 15 | "test:node": "node test/moment-parseformat-test.js", 16 | "presemantic-release": "npm run build", 17 | "semantic-release": "semantic-release" 18 | }, 19 | "files": [ 20 | "lib", 21 | "dist", 22 | "index.js" 23 | ], 24 | "repository": "github:gr2m/moment-parseformat", 25 | "author": "Gregor Martynus ", 26 | "license": "MIT", 27 | "homepage": "http://gr2m.github.io/moment-parseformat", 28 | "devDependencies": { 29 | "beefy": "^2.1.5", 30 | "browserify": "^16.0.0", 31 | "gh-pages-deploy": "^0.5.0", 32 | "istanbul": "^0.4.0", 33 | "istanbul-coveralls": "^1.0.1", 34 | "mkdirp": "^1.0.0", 35 | "moment": "^2.10.6", 36 | "rimraf": "^3.0.0", 37 | "semantic-release": "^17.0.0", 38 | "standard": "^16.0.3", 39 | "tap-spec": "^5.0.0", 40 | "tape": "^5.0.0" 41 | }, 42 | "keywords": [ 43 | "momentjs", 44 | "date", 45 | "parse", 46 | "format" 47 | ], 48 | "gh-pages-deploy": { 49 | "staticpath": "demo", 50 | "noprompt": true 51 | }, 52 | "standard": { 53 | "ignore": [ 54 | "demo" 55 | ] 56 | }, 57 | "version": "1.0.0" 58 | } 59 | --------------------------------------------------------------------------------