pax_global_header 0000666 0000000 0000000 00000000064 14032634405 0014513 g ustar 00root root 0000000 0000000 52 comment=b0f5695f4ec48d79e381c056fc6f4dda29025b43
fecha-4.2.1/ 0000775 0000000 0000000 00000000000 14032634405 0012565 5 ustar 00root root 0000000 0000000 fecha-4.2.1/.babelrc 0000664 0000000 0000000 00000000203 14032634405 0014153 0 ustar 00root root 0000000 0000000 {
"presets": [
[
"@babel/preset-env"
]
],
"plugins": ["@babel/plugin-proposal-optional-chaining"]
} fecha-4.2.1/.browserslistrc 0000664 0000000 0000000 00000000010 14032634405 0015644 0 ustar 00root root 0000000 0000000 defaults fecha-4.2.1/.editorconfig 0000664 0000000 0000000 00000000267 14032634405 0015247 0 ustar 00root root 0000000 0000000 # top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
fecha-4.2.1/.eslintrc.js 0000664 0000000 0000000 00000000521 14032634405 0015022 0 ustar 00root root 0000000 0000000 module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
rules: {
"@typescript-eslint/ban-ts-ignore": "off"
}
};
fecha-4.2.1/.gitignore 0000664 0000000 0000000 00000000050 14032634405 0014550 0 ustar 00root root 0000000 0000000 node_modules
coverage
.nyc_output
ts-out fecha-4.2.1/.nycrc 0000664 0000000 0000000 00000000066 14032634405 0013706 0 ustar 00root root 0000000 0000000 {
"extends": "@istanbuljs/nyc-config-typescript"
} fecha-4.2.1/.travis.yml 0000664 0000000 0000000 00000000045 14032634405 0014675 0 ustar 00root root 0000000 0000000 language: node_js
node_js:
- 12.14
fecha-4.2.1/CHANGELOG.md 0000664 0000000 0000000 00000003651 14032634405 0014403 0 ustar 00root root 0000000 0000000 ### 4.2.1
- Fixed missing source map
- Fixed security y18n
### 4.2.0
Added isoDate and isoDateTime masks
### 4.1.0
Added Z format/parse and fixed Peru timezone issue
- Added `Z` format token. See readme for more info. Big thanks to @fer22f for writing the code.
- Fixed a strange issue when Peru changed timezones in 1990. See #78
## 4.0.0
**Major Features and Breaking changes in this version**
#### Improvements
- *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
- *ES Module and Tree Shaking Support* - You can now import fecha `parse` or `format` independently
```js
import {format, parse} from 'fecha';
format(...);
parse(...)
```
#### Breaking changes
- `parseDate` may return `null` when previously returned a `Date`. See improvements above, but invalid dates will return `null` now
- Change to how to set masks and i18n
Previously
```js
import fecha from 'fecha';
fecha.i18n = { ... }
fecha.masks.myMask = 'DD , MM, YYYY'
```
New
```js
import {parse, format, setGlobalDateI18n, setGlobalDateMasks} from 'fecha';
setGlobalDateI18n({
// ...
})
setGlobalDateMasks({
myMask: 'DD , MM, YYYY'
});
```
### 3.0.3
- Fixed bug when using brackets when parsing dates
### 3.0.2
- Fixed issue where src files are not included correctly in npm
### 3.0.0
- Moved to ES modules
- Changed invalid date from `false` to `null`
### 2.3.3
Fixed bug with year 999 not having leading zero
### 2.3.2
Added typescript definitions to NPM
### 2.3.0
Added strict version of date parser that returns null on invalid dates (may use strict version in v3)
### 2.2.0
Fixed a bug when parsing Do format dates
## 2.0.0
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]'`.
fecha-4.2.1/CONTRIBUTING.md 0000664 0000000 0000000 00000002152 14032634405 0015016 0 ustar 00root root 0000000 0000000 # Contributing
We are open to, and grateful for, any contributions made by the community.
## Reporting Issues and Asking Questions
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.
## Development
Visit the [Issue tracker](https://github.com/taylorhakes/fecha/issues) to find a list of open issues that need attention.
Fork, then clone the repo:
```
git clone https://github.com/your-username/fecha.git
```
### New Features
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.
## Submitting Changes
* Open a new issue in the [Issue tracker](https://github.com/taylorhakes/fecha/issues).
* Fork the repo.
* Create a new feature branch based off the `master` branch.
* Make sure all tests pass and there are no linting errors.
* Submit a pull request, referencing any issues it addresses.
Please try to keep your pull request focused in scope and avoid including unrelated commits.
fecha-4.2.1/LICENSE 0000664 0000000 0000000 00000002070 14032634405 0013571 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2015 Taylor Hakes
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
fecha-4.2.1/README.md 0000664 0000000 0000000 00000016760 14032634405 0014056 0 ustar 00root root 0000000 0000000 # fecha [](https://travis-ci.org/taylorhakes/fecha)
Lightweight date formatting and parsing (~2KB). Meant to replace parsing and formatting functionality of moment.js.
### NPM
```
npm install fecha --save
```
### Yarn
```
yarn add fecha
```
### Fecha vs Moment
|
Fecha |
Moment |
Size (Min. and Gzipped) |
2.1KBs |
13.1KBs |
Date Parsing |
✓ |
✓ |
Date Formatting |
✓ |
✓ |
Date Manipulation |
|
✓ |
I18n Support |
✓ |
✓ |
## Use it
#### Formatting
`format` accepts a Date object (or timestamp) and a string format and returns a formatted string. See below for
available format tokens.
Note: `format` will throw an error when passed invalid parameters
```js
import { format } from 'fecha';
type format = (date: Date, format?: string, i18n?: I18nSettings) => str;
// Custom formats
format(new Date(2015, 10, 20), 'dddd MMMM Do, YYYY'); // 'Friday November 20th, 2015'
format(new Date(1998, 5, 3, 15, 23, 10, 350), 'YYYY-MM-DD hh:mm:ss.SSS A'); // '1998-06-03 03:23:10.350 PM'
// Named masks
format(new Date(2015, 10, 20), 'isoDate'); // '2015-11-20'
format(new Date(2015, 10, 20), 'mediumDate'); // 'Nov 20, 2015'
format(new Date(2015, 10, 20, 3, 2, 1), 'isoDateTime'); // '2015-11-20T03:02:01-05:00'
format(new Date(2015, 2, 10, 5, 30, 20), 'shortTime'); // '05:30'
// Literals
format(new Date(2001, 2, 5, 6, 7, 2, 5), '[on] MM-DD-YYYY [at] HH:mm'); // 'on 03-05-2001 at 06:07'
```
#### Parsing
`parse` accepts a Date string and a string format and returns a Date object. See below for available format tokens.
*NOTE*: `parse` will throw an error when passed invalid string format or missing format. You MUST specify a format.
```js
import { parse } from 'fecha';
type parse = (dateStr: string, format: string, i18n?: I18nSettingsOptional) => Date|null;
// Custom formats
parse('February 3rd, 2014', 'MMMM Do, YYYY'); // new Date(2014, 1, 3)
parse('10-12-10 14:11:12', 'YY-MM-DD HH:mm:ss'); // new Date(2010, 11, 10, 14, 11, 12)
// Named masks
parse('5/3/98', 'shortDate'); // new Date(1998, 4, 3)
parse('November 4, 2005', 'longDate'); // new Date(2005, 10, 4)
parse('2015-11-20T03:02:01-05:00', 'isoDateTime'); // new Date(2015, 10, 20, 3, 2, 1)
// Override i18n
parse('4 de octubre de 1983', 'M de MMMM de YYYY', {
monthNames: [
'enero',
'febrero',
'marzo',
'abril',
'mayo',
'junio',
'julio',
'agosto',
'septiembre',
'octubre',
'noviembre',
'diciembre'
]
}); // new Date(1983, 9, 4)
```
#### i18n Support
```js
import {setGlobalDateI18n} from 'fecha';
/*
Default I18n Settings
{
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'],
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
amPm: ['am', 'pm'],
// D is the day of the month, function returns something like... 3rd or 11th
DoFn(dayOfMonth) {
return dayOfMonth + [ 'th', 'st', 'nd', 'rd' ][ dayOfMonth % 10 > 3 ? 0 : (dayOfMonth - dayOfMonth % 10 !== 10) * dayOfMonth % 10 ];
}
}
*/
setGlobalDateI18n({
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'],
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
amPm: ['am', 'pm'],
// D is the day of the month, function returns something like... 3rd or 11th
DoFn: function (D) {
return D + [ 'th', 'st', 'nd', 'rd' ][ D % 10 > 3 ? 0 : (D - D % 10 !== 10) * D % 10 ];
}
});
```
#### Custom Named Masks
```js
import { format, setGlobalDateMasks } from 'fecha';
/*
Default global masks
{
default: 'ddd MMM DD YYYY HH:mm:ss',
shortDate: 'M/D/YY',
mediumDate: 'MMM D, YYYY',
longDate: 'MMMM D, YYYY',
fullDate: 'dddd, MMMM D, YYYY',
shortTime: 'HH:mm',
mediumTime: 'HH:mm:ss',
longTime: 'HH:mm:ss.SSS'
}
*/
// Create a new mask
setGlobalDateMasks({
myMask: 'HH:mm:ss YY/MM/DD';
});
// Use it
format(new Date(2014, 5, 6, 14, 10, 45), 'myMask'); // '14:10:45 14/06/06'
```
### Formatting Tokens
|
Token |
Output |
Month |
M |
1 2 ... 11 12 |
|
MM |
01 02 ... 11 12 |
|
MMM |
Jan Feb ... Nov Dec |
|
MMMM |
January February ... November December |
Day of Month |
D |
1 2 ... 30 31 |
|
Do |
1st 2nd ... 30th 31st |
|
DD |
01 02 ... 30 31 |
Day of Week |
d |
0 1 ... 5 6 |
|
ddd |
Sun Mon ... Fri Sat |
|
dddd |
Sunday Monday ... Friday Saturday |
Year |
YY |
70 71 ... 29 30 |
|
YYYY |
1970 1971 ... 2029 2030 |
AM/PM |
A |
AM PM |
|
a |
am pm |
Hour |
H |
0 1 ... 22 23 |
|
HH |
00 01 ... 22 23 |
|
h |
1 2 ... 11 12 |
|
hh |
01 02 ... 11 12 |
Minute |
m |
0 1 ... 58 59 |
|
mm |
00 01 ... 58 59 |
Second |
s |
0 1 ... 58 59 |
|
ss |
00 01 ... 58 59 |
Fractional Second |
S |
0 1 ... 8 9 |
|
SS |
0 1 ... 98 99 |
|
SSS |
0 1 ... 998 999 |
Timezone |
Z |
-07:00 -06:00 ... +06:00 +07:00
|
|
ZZ |
-0700 -0600 ... +0600 +0700
|
fecha-4.2.1/bower.json 0000664 0000000 0000000 00000001367 14032634405 0014605 0 ustar 00root root 0000000 0000000 {
"name": "fecha",
"main": "fecha.js",
"version": "2.3.2",
"homepage": "https://github.com/taylorhakes/fecha",
"authors": [
"Taylor Hakes"
],
"description": "Date formatting and parsing",
"moduleType": [
"amd",
"globals",
"node"
],
"keywords": [
"date",
"parse",
"moment",
"format",
"fecha",
"formatting"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"devDependencies": {
"karma": "^0.12.31",
"jasmine-core": "^2.1.3",
"karma-jasmine": "^0.3.4",
"karma-phantomjs-launcher": "^0.1.4",
"karma-coverage": "^0.2.7",
"gulp": "^3.8.10",
"gulp-uglify": "^1.0.2",
"gulp-rename": "^1.2.0"
}
}
fecha-4.2.1/dist/ 0000775 0000000 0000000 00000000000 14032634405 0013530 5 ustar 00root root 0000000 0000000 fecha-4.2.1/dist/fecha.min.js 0000664 0000000 0000000 00000014015 14032634405 0015717 0 ustar 00root root 0000000 0000000 !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.fecha={})}(this,function(t){"use strict";var n=/d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|Z|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g,e="[^\\s]+",r=/\[([^]*?)\]/gm;function o(t,n){for(var e=[],r=0,o=t.length;r-1?r:null}};function a(t){for(var n=[],e=1;e3?0:(t-t%10!=10?1:0)*t%10]}},m=a({},f),c=function(t){return m=a(m,t)},l=function(t){return t.replace(/[|\\{()[^$+*?.-]/g,"\\$&")},h=function(t,n){for(void 0===n&&(n=2),t=String(t);t.length0?"-":"+")+h(100*Math.floor(Math.abs(n)/60)+Math.abs(n)%60,4)},Z:function(t){var n=t.getTimezoneOffset();return(n>0?"-":"+")+h(Math.floor(Math.abs(n)/60),2)+":"+h(Math.abs(n)%60,2)}},M=function(t){return+t-1},D=[null,"[1-9]\\d?"],Y=[null,e],p=["isPm",e,function(t,n){var e=t.toLowerCase();return e===n.amPm[0]?0:e===n.amPm[1]?1:null}],y=["timezoneOffset","[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z?",function(t){var n=(t+"").match(/([+-]|\d\d)/gi);if(n){var e=60*+n[1]+parseInt(n[2],10);return"+"===n[0]?e:-e}return 0}],S={D:["day","[1-9]\\d?"],DD:["day","\\d\\d"],Do:["day","[1-9]\\d?"+e,function(t){return parseInt(t,10)}],M:["month","[1-9]\\d?",M],MM:["month","\\d\\d",M],YY:["year","\\d\\d",function(t){var n=+(""+(new Date).getFullYear()).substr(0,2);return+(""+(+t>68?n-1:n)+t)}],h:["hour","[1-9]\\d?",void 0,"isPm"],hh:["hour","\\d\\d",void 0,"isPm"],H:["hour","[1-9]\\d?"],HH:["hour","\\d\\d"],m:["minute","[1-9]\\d?"],mm:["minute","\\d\\d"],s:["second","[1-9]\\d?"],ss:["second","\\d\\d"],YYYY:["year","\\d{4}"],S:["millisecond","\\d",function(t){return 100*+t}],SS:["millisecond","\\d\\d",function(t){return 10*+t}],SSS:["millisecond","\\d{3}"],d:D,dd:D,ddd:Y,dddd:Y,MMM:["month",e,u("monthNamesShort")],MMMM:["month",e,u("monthNames")],a:p,A:p,ZZ:y,Z:y},v={default:"ddd MMM DD YYYY HH:mm:ss",shortDate:"M/D/YY",mediumDate:"MMM D, YYYY",longDate:"MMMM D, YYYY",fullDate:"dddd, MMMM D, YYYY",isoDate:"YYYY-MM-DD",isoDateTime:"YYYY-MM-DDTHH:mm:ssZ",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"},H=function(t){return a(v,t)},b=function(t,e,o){if(void 0===e&&(e=v.default),void 0===o&&(o={}),"number"==typeof t&&(t=new Date(t)),"[object Date]"!==Object.prototype.toString.call(t)||isNaN(t.getTime()))throw new Error("Invalid Date pass to format");var u=[];e=(e=v[e]||e).replace(r,function(t,n){return u.push(n),"@@@"});var i=a(a({},m),o);return(e=e.replace(n,function(n){return g[n](t,i)})).replace(/@@@/g,function(){return u.shift()})};function w(t,e,o){if(void 0===o&&(o={}),"string"!=typeof e)throw new Error("Invalid format in fecha parse");if(e=v[e]||e,t.length>1e3)return null;var u={year:(new Date).getFullYear(),month:0,day:1,hour:0,minute:0,second:0,millisecond:0,isPm:null,timezoneOffset:null},i=[],d=[],s=e.replace(r,function(t,n){return d.push(l(n)),"@@@"}),f={},c={};s=l(s).replace(n,function(t){var n=S[t],e=n[0],r=n[1],o=n[3];if(f[e])throw new Error("Invalid format. "+e+" specified twice in format");return f[e]=!0,o&&(c[o]=!0),i.push(n),"("+r+")"}),Object.keys(c).forEach(function(t){if(!f[t])throw new Error("Invalid format. "+t+" is required in specified format")}),s=s.replace(/@@@/g,function(){return d.shift()});var h=t.match(new RegExp(s,"i"));if(!h)return null;for(var g=a(a({},m),o),M=1;M