Skip to content

Commit

Permalink
Init project.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 7, 2019
0 parents commit 85edc7e
Show file tree
Hide file tree
Showing 12 changed files with 6,631 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": ["@babel/preset-env"],
"plugins": [
"@babel/plugin-transform-runtime"
]
}
10 changes: 10 additions & 0 deletions .editorconfig
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
19 changes: 19 additions & 0 deletions .gitignore
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
*.*~
~*.*
22 changes: 22 additions & 0 deletions .npmignore
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
14 changes: 14 additions & 0 deletions .travis.yml
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
79 changes: 79 additions & 0 deletions README.md
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` |
Loading

0 comments on commit 85edc7e

Please sign in to comment.