Skip to content

Commit 5597efa

Browse files
committed
Merge branch 'develop' into master
2 parents 6f726d9 + c158464 commit 5597efa

File tree

7 files changed

+285
-130
lines changed

7 files changed

+285
-130
lines changed

README.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,23 @@ npm install date-and-time --save
3232

3333
## Recent Changes
3434

35+
- 0.14.1
36+
- Fixed a bug characters inside square brackets `[]` are not validated.
37+
3538
- 0.14.0
3639
- **Feature Freeze**
3740

3841
We decided to freeze the feature with this version (except the following). The next will be 1.0.0.
3942

4043
- To support `ES Modules` (without transpile) in the next version, the importing method has changed in the `locale()` and the `plugin()`. As this version you will see the warning message if using the old method. See [LOCALE.md](./LOCALE.md) and [PLUGINS.md](./PLUGINS.md) for details.
4144

42-
- Added `transform()` function to transform the format of a date string. When changing the format, in the past you would convert the date string to a date object with the `parse()`, and then format it with the `format()` again, but you can now do this with a single function.
45+
- Added `transform()` function to transform the format of a date string. When changing the format, previously you would convert the date string to a date object with the `parse()`, and then format it with the `format()` again, but you can now do this with a single function.
4346

4447
```javascript
4548
// 3/8/2020 => 8/3/2020
4649
date.transform('3/8/2020', 'D/M/YYYY', 'M/D/YYYY');
4750

48-
// in the past
51+
// previously
4952
const today = date.parse('3/8/2020', 'D/M/YYYY');
5053
date.format(today, 'M/D/YYYY'); // => '8/3/2020'
5154
```
@@ -105,18 +108,6 @@ npm install date-and-time --save
105108

106109
- Added `microsecond` plugin for the parser. Microsecond is not supported by date objects so that it is rounded `millisecond` at the inside. See [PLUGINS.md](./PLUGINS.md) for details.
107110

108-
- 0.12.0
109-
- The parser now supports `Z` token to parse timezone offset.
110-
- (**Breaking Change**) **Excleded `YY` token from the parser**, added it as `two-digit-year` plugin. See [PLUGINS.md](./PLUGINS.md) for details.
111-
- (**Breaking Change**) Decided to **change the default behavior of `A` token** to fix the non-intuitive definition. Sepcifically, in the `format()` it now outputs `AM` / `PM` instead of `a.m.` / `p.m.`, and in the `parse()` it recognizes `AM` / `PM` only. Other `A` tokens are supported as `meridiem` plugin.
112-
113-
| token | new meaning | example | default |
114-
|:------|:-----------------------------------|:-----------|:--------|
115-
| A | meridiem (uppercase) | AM, PM | ✔️ |
116-
| AA | meridiem (uppercase with ellipsis) | A.M., P.M. | |
117-
| a | meridiem (lowercase) | am, pm | |
118-
| aa | meridiem (lowercase with ellipsis) | a.m., p.m. | |
119-
120111
## Usage
121112

122113
- Node.js:
@@ -328,9 +319,9 @@ date.parse('11:14:05', 'hh:mm:ss'); // => Jan 1 1970 11:14:05 GMT-0800
328319
date.parse('11:14:05 PM', 'hh:mm:ss A'); // => Jan 1 1970 23:14:05 GMT-0800
329320
```
330321

331-
#### NOTE 6. Comments
322+
#### NOTE 6. Token disablement
332323

333-
String in parenthese `[...]` in the `formatString` will be ignored as comments:
324+
Use square brackets `[]` if a date-time string includes some token characters. Tokens inside square brackets in the `formatString` will be interpreted as normal characters:
334325

335326
```javascript
336327
date.parse('12 hours 34 minutes', 'HH hours mm minutes'); // => Invalid Date

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "date-and-time",
33
"description": "A Minimalist DateTime utility for Node.js and the browser",
4-
"version": "0.14.0",
4+
"version": "0.14.1",
55
"main": "date-and-time.js",
66
"moduleType": [
77
"amd",

date-and-time.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
date.preparse = function (dateString, arg) {
174174
var pattern = typeof arg === 'string' ? date.compile(arg) : arg,
175175
dt = { Y: 1970, M: 1, D: 1, H: 0, A: 0, h: 0, m: 0, s: 0, S: 0, Z: 0, _index: 0, _length: 0, _match: 0 },
176-
parser = locales[lang].parser, offset = 0;
176+
comment = /\[(.*)]/, parser = locales[lang].parser, offset = 0;
177177

178178
dateString = parser.pre(dateString);
179179
for (var i = 1, len = pattern.length, token, result; i < len; i++) {
@@ -188,7 +188,7 @@
188188
dt._match++;
189189
} else if (token === dateString.charAt(offset) || token === ' ') {
190190
offset++;
191-
} else if (/\[.*]/.test(token)) {
191+
} else if (comment.test(token) && !dateString.slice(offset).indexOf(comment.exec(token)[1])) {
192192
offset += token.length - 2;
193193
} else if (token === '...') {
194194
offset = dateString.length;

date-and-time.min.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)