Skip to content

Commit

Permalink
Merge branch 'develop' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
knowledgecode committed Aug 23, 2020
2 parents 6f726d9 + c158464 commit 5597efa
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 130 deletions.
23 changes: 7 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ npm install date-and-time --save

## Recent Changes

- 0.14.1
- Fixed a bug characters inside square brackets `[]` are not validated.

- 0.14.0
- **Feature Freeze**

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

- 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.

- 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.
- 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.

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

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

- 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.

- 0.12.0
- The parser now supports `Z` token to parse timezone offset.
- (**Breaking Change**) **Excleded `YY` token from the parser**, added it as `two-digit-year` plugin. See [PLUGINS.md](./PLUGINS.md) for details.
- (**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.

| token | new meaning | example | default |
|:------|:-----------------------------------|:-----------|:--------|
| A | meridiem (uppercase) | AM, PM | ✔️ |
| AA | meridiem (uppercase with ellipsis) | A.M., P.M. | |
| a | meridiem (lowercase) | am, pm | |
| aa | meridiem (lowercase with ellipsis) | a.m., p.m. | |

## Usage

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

#### NOTE 6. Comments
#### NOTE 6. Token disablement

String in parenthese `[...]` in the `formatString` will be ignored as comments:
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:

```javascript
date.parse('12 hours 34 minutes', 'HH hours mm minutes'); // => Invalid Date
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "date-and-time",
"description": "A Minimalist DateTime utility for Node.js and the browser",
"version": "0.14.0",
"version": "0.14.1",
"main": "date-and-time.js",
"moduleType": [
"amd",
Expand Down
4 changes: 2 additions & 2 deletions date-and-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
date.preparse = function (dateString, arg) {
var pattern = typeof arg === 'string' ? date.compile(arg) : arg,
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 },
parser = locales[lang].parser, offset = 0;
comment = /\[(.*)]/, parser = locales[lang].parser, offset = 0;

dateString = parser.pre(dateString);
for (var i = 1, len = pattern.length, token, result; i < len; i++) {
Expand All @@ -188,7 +188,7 @@
dt._match++;
} else if (token === dateString.charAt(offset) || token === ' ') {
offset++;
} else if (/\[.*]/.test(token)) {
} else if (comment.test(token) && !dateString.slice(offset).indexOf(comment.exec(token)[1])) {
offset += token.length - 2;
} else if (token === '...') {
offset = dateString.length;
Expand Down
18 changes: 9 additions & 9 deletions date-and-time.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5597efa

Please sign in to comment.