-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 85edc7e
Showing
12 changed files
with
6,631 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": ["@babel/preset-env"], | ||
"plugins": [ | ||
"@babel/plugin-transform-runtime" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
; editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/cjs | ||
/esm | ||
/dist | ||
/node_modules | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
.DS_Store | ||
.cache | ||
.vscode | ||
|
||
*.bak | ||
*.tem | ||
*.temp | ||
#.swp | ||
*.swo | ||
*.*~ | ||
~*.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
src | ||
test | ||
npm-debug.log | ||
package-lock.json | ||
yarn.lock | ||
rollup.config.js | ||
tsconfig.json | ||
|
||
.DS_Store | ||
.vscode | ||
.travis.yml | ||
.babelrc | ||
.stylelintrc | ||
.eslintrc | ||
.editorconfig | ||
.gitignore | ||
|
||
*.swp | ||
*.swo | ||
*.log | ||
*.log.* | ||
*.json.gzip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: node_js | ||
node_js: | ||
- 9.8.0 | ||
cache: | ||
directories: | ||
- node_modules | ||
before_script: | ||
- npm install codecov.io coveralls | ||
after_success: | ||
- cat ./coverage/lcov.info | ./node_modules/codecov.io/bin/codecov.io.js | ||
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js | ||
script: | ||
- npm run build | ||
- node --harmony ./node_modules/.bin/jest --coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
formatter | ||
--- | ||
|
||
Get a formatted date. | ||
|
||
### Install | ||
|
||
```bash | ||
$ npm install --save @uiw/formatter | ||
``` | ||
|
||
### Usage | ||
|
||
```js | ||
import formatter from '@uiw/formatter'; | ||
|
||
console.log(formatter()); | ||
//=> 2019-03-07 | ||
|
||
console.log(formatter.utc()); | ||
//=> 2019-03-07 | ||
|
||
console.log(formatter('YYYY年MM月DD日', new Date(2019, 3, 7))) | ||
//=> 2019年04月07日 | ||
console.log(formatter('YYYY年MM月DD日 16:30:29', new Date(2019, 3, 7, 16, 30, 29))) | ||
//=> 2019年04月07日 16:30:29 | ||
|
||
|
||
console.log(formatter('YYYY')); | ||
//=> 2019 | ||
console.log(formatter.utc('YYYY')); | ||
//=> 2019 | ||
``` | ||
|
||
Or manually download and link **formatter.js** in your HTML, It can also be downloaded via [UNPKG](https://unpkg.com/@uiw/formatter): | ||
|
||
```html | ||
<div id="date"></div> | ||
<script src="https://unpkg.com/@uiw/formatter/dist/formatter.min.js"></script> | ||
<script> | ||
document.getElementById('date').innerHTML = formatter(); | ||
</script> | ||
``` | ||
|
||
### timeZoneConverter | ||
|
||
Resolve changes in time zone, resulting in inaccurate display server time | ||
|
||
```js | ||
function timeZoneConverter(date, timeZone) { | ||
const oldDate = new Date(date); | ||
const newDate = new Date(); | ||
const stamp = oldDate.getTime(); | ||
if (!timeZone) return oldDate; | ||
return (isNaN(timeZone) && !timeZone) | ||
? oldDate : | ||
new Date(stamp + (newDate.getTimezoneOffset() * 60 * 1000) + (timeZone * 60 * 60 * 1000)); | ||
} | ||
timeZoneConverter(new Date(1434701732*1000), 8) | ||
``` | ||
|
||
## API | ||
|
||
```js | ||
formatter(rule: String, date: Date, utc: Boolean); | ||
formatter.utc(rule: String, date: Date); | ||
``` | ||
|
||
## Supported Patterns | ||
|
||
| rule | Description | 中文说明 | E.g | | ||
|--------- |-------- |--------- |-------- | | ||
| `YYYY` | full year | 年 | `2019` | | ||
| `MM` | month | 月 | `02` | | ||
| `DD` | day | 天 | `05` | | ||
| `HH` | hours | 时 | `12` | | ||
| `mm` | minutes | 分钟 | `59` | | ||
| `ss` | seconds | 秒 | `09` | | ||
| `ms` | milliseconds | 毫秒 | `532` | |
Oops, something went wrong.