Giter Club home page Giter Club logo

timecall's Introduction

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( )
  • ago( )
  • left( )

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

Pattern Description
EEEE Day of the week
MM Month of the year in a two-digit format
MMM Abbreviated month of the year
MMMM Month of the year
DD Day of the month with leading zero
d Day of the month
yy Year in two-digit format
yyyy Year in four-digit format
YYYY Week-based year
HH Hour of the day (0-23)
hh Clock hour in AM/PM (1-12) format with leading zero 02:15
h Clock hour in AM/PM (1-12) format without leading zero 2:15
mm Minute with leading zero
m Minute without leading zero
ss Second
a AM/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

timecall's People

Contributors

indaneey avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.