@aiursoft/utctime.js
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

UtcTime.js

MIT licensed Pipeline stat ManHours npm npm

@aiursoft/utctime.js is a JavaScript library which converts UTC time to local time easily.

Installation

Run the following command to install the most recent version of @aiursoft/utctime.js from npm:

npm install @aiursoft/utctime.js

Importing

Reference JavaScript

You can import the library using the following code:

<script type="module">
  import UtcTime from './node_modules/@aiursoft/utctime.js/dist/esm/utctime.js'
  new UtcTime({})
</script>

How to build locally

npm install
npm run build

How to use

Create an element.

<p></p>

And change it like this.

<p data-utc-time="9/12/2018 10:12:24 AM"><!-- In your tag the time shall be an UTC time --></p>

Add init jquery-utc-time

<script>
  new UtcTime({})
</script>

And open it now! The time will be converted to local time.

API

// Init with loop
new UtcTime({
  // We will try to select elements using the attr value. Default value is 'data-utc-time'.
  attr: 'data-utc-time',

  // Localization options. Default is ' days ago'
  daysAgo: '天前',

  // Localization options. Default is ' hours ago'
  hoursAgo: '小时前',

  // Localization options. Default is ' mintes ago'
  minutesAgo: '分钟前',

  // Localization options. Default is ' seconds ago'
  secondsAgo: '秒前',

  // Always display time and date not `some time` ago.
  disableAgo: false,

  // After the content is replaced.
  onSet: function (element, date) {},

  // Disable auto update the value by seconds.
  disableAutoUpdate: false,
})

For example, to init bootstrap v4 tooltip:

new UtcTime({
  onSet: function (element, date) {
    element.setAttribute('data-toggle', 'tooltip')
    element.setAttribute('data-trigger', 'hover')
    element.setAttribute('data-title', date.toLocaleString())
    $(element).tooltip()
  },
})

To init bootstrap v5 tooltip:

new UtcTime({
  onSet: function (element, date) {
    element.setAttribute('data-bs-toggle', 'tooltip')
    element.setAttribute('data-bs-trigger', 'hover')
    element.setAttribute('data-bs-title', date.toLocaleString())
    var tooltip = new bootstrap.Tooltip(element)
  },
})

How to contribute

There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.

Even if you with push rights on the repository, you should create a personal fork and create feature branches there when you need them. This keeps the main repository clean and your workflow cruft out of sight.

We're also interested in your feedback on the future of this project. You can submit a suggestion or feature request through the issue tracker. To make this process more effective, we're asking that these include more information to help define them more clearly.

Readme

Keywords

none

Package Sidebar

Install

npm i @aiursoft/utctime.js

Weekly Downloads

3

Version

1.0.4

License

MIT

Unpacked Size

16.8 kB

Total Files

11

Last publish

Collaborators

  • anduin2017