1.0.0 • Published 2 years ago

@indaneey/timecall v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

timeCall.js

timeCall.js is a simple library that used to get a human readable form of date object.

Installation

# Basic Node.JS installation
npm install @indaneey/timecall --save

Syntax

Import timecall() as component

import { timeCall } from '@indaneey/timecall';

Examples

Calling timecall using require()

var timeCall = require('timecall');
var timenow = new timeCall();

Import the minified version of timeCall.min.js JavaScript library

<head>
<script src="timecall.min.js"></script>
</head>

and then in script tag create timeCall() instance

var timenow = new timeCall();

Initialize the timeCall with date parameter


  var timenow = new timeCall('2021/05/02 5:45:25') // or JavaScript Date object

timeCall methods

format() method

use this method to easly formatted Date object, this method takes two parameters the first one is Date and Time format pattern and second is some properties

Example

  var timenow = new timeCall(Date.now())
  timenow.format("DD MM YYYY hh mm a") // returns 03/11/2021 05:02AM
  timenow.format("EEEE DD MMMM YYYY HH mm") // returns Wednesday, 03 November 2021 15:02

You have to seperate each pattern by space.

This method has two properties

  • datedivider
  • timedivider

Example

    var timenow = new timeCall(Date.now())
    timenow.format("DD MM YYYY hh mm a", {
      datedivider: "-", // returns 03-11-2021 - this property will change the date divider sign
      timedivider: ":"  // returns 05:02AM - this property will change the time divider sign
    })

List of all Date and Time Pattern

PatternDescription
EEEEDay of the week
MMMonth of the year in a two-digit format
MMMAbbreviated month of the year
MMMMMonth of the year
DDDay of the month with leading zero
dDay of the month
yyYear in two-digit format
yyyyYear in four-digit format
YYYYWeek-based year
HHHour of the day (0-23)
hhClock hour in AM/PM (1-12) format with leading zero 02:15
hClock hour in AM/PM (1-12) format without leading zero 2:15
mmMinute with leading zero
mMinute without leading zero
ssSecond
aAM/PM marker

ago() method

use this method to get how long the date is passed, like 1 day ago and it will returns either string or object with date details.

Example

var ago = new timeCall('2022/05/02 12:20').ago() // returns 2 days 5 hours 26 minutes 47 seconds ago

This method has some properties

  • withtime
  • timeformat
  • json

Example of withtime and timeformat

  var timecall = new timeCall('2022/05/02 12:20').ago({
      withtime: true, // this will enable time or unable it
      timeformat:  "hh:mm", // this property will change the time format. "hh", "hh:mm" and "hh:mm:ss"
  }) // returns 2 days 5 hours 40 minutes ago

Example of json property this will return an object with the date and time details.

  var timecall = new timeCall('2022/05/02 12:20').ago({
    json: true // this will return json type date with the Date and Time details
  }) // returns { success: true, action: "ago", data: { days: 2, hours: 5, minutes: 42 }}

left() method

use this method to get how long the date is left, like 1 day 6 hours 34 minutes left and it will returns either string or object with date details.

Example

var left = new timeCall('2024/05/03 12:50').left() // returns 2 years 18 hours 38 minutes 12 seconds left

This method has some properties the same with ago() above

  • withtime
  • timeformat
  • json

timeCall.js

Developed by Indaneey_design. for any support contact me here