1.14.9 • Published 2 years ago

format_date_time_moment v1.14.9

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

THIS MODULE HAS BEEN DEPRECIATED AND HAS BEEN MOVED TO THIS INSTEAD:

when_you_free

  • what this means: this package will still work, but it won't be as organized and won't be updated.
  • more practically, check out when_you_free - it has all these functionalities and more.

NPM Downloads

format_date_time_moment

The purpose is to make it easier to format dates (given whatever input the date may be in)

Table of Contents

Install

Directions

  1. Install the package
npm install format_date_time_moment

If utilizing in node, import into your javascript file like such

pay attention to the format_date_time_moment/node here

const {formatDateTime} = require("format_date_time_moment/node")

otherwise...

  1. In your html document, import the script (make sure to import it after your JQuery AND moment script, and before your javascript file)
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.js' integrity='sha512-Bm8FBfOFILW7qzf514l/KJaW+VKYyErRPjBRcpCJ1IfmBJcL9PRSBo6fyhE0i8BBmBbiMyQrNC97m1b1dDWM0g==' crossorigin='anonymous'></script>
    <script src='https://cdn.jsdelivr.net/npm/format_date_time_moment/index.js' type='text/javascript'></script>
  1. Create javascript file - make sure to put all your jquery selectors after the instantiator - e.g.,
$(() => {
   console.log(formatDateTime.getType("2022-03-01T19:06:31.047Z"))
})
<script src="yourScript.js"></script>

API

## FormatDateTime Kind: global class
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11

new FormatDateTime()

let formatDateTime = new FormatDateTime()

formatDateTime.getType(date) ⇒ any

Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11

ParamType
dateany

Example

getType(Date)
"2022-03-01T19:06:31.047Z"
         "00:22:00"
         "March 1, 2022"
         "Mar 1, 2022"
         "2022-03-01"
         "01-03-2022"
         "2022/03/01"
         new Date()
         23

formatDateTime.catchError(getDate) ⇒ any

catchError(date) Sees if getDate is undefined or not an object. if so, return const ERROR_OBJECT = { error: "not valid date", error_location: "format_date_time_moment", message: "date error" }

Kind: instance method of FormatDateTime
Date: 2022-03-01

ParamType
getDateany

formatDateTime.isBefore(start, end) ⇒ boolean

Good to use if you want to see a date is before another

Kind: instance method of FormatDateTime
Date: 2022-01-20
Author: lezzles11 :) www.github.com/lezzles11

ParamType
startany
endany

Example

console.log(formatDateTime.isBetween("March 3, 2020", "March 10, 2021"))

formatDateTime.getDuration(start, end, type) ⇒ integer

Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11

ParamType
startany
endany
typeany

Example

console.log(formatDateTime.getDuration("2022-03-01T19:06:31.047Z", "2022-03-01T20:04:32.047Z", "seconds")) // 3481
         console.log(formatDateTime.getDuration("2022-04-01T19:06:31.047Z", "2022-06-01T20:04:32.047Z", "days")) // 61.040289351851854

formatDateTime.getReadableFormat(getDate, type) ⇒ string

Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11

ParamTypeDefault
getDateany
typeanyfrom

Example

getReadableFormat("Dec 11, 2012", "from") in 2 months
getReadableFormat("Dec 11, 2012", "to") 2 months ago

formatDateTime.difference(one, two, type) ⇒ integer

Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11

ParamType
oneany
twoany
typeany

Example

console.log(formatDateTime.difference("00:22:00", "00:44:00", "seconds"))
         console.log(formatDateTime.difference("March 1, 2020", "March 1, 2021", "months"))

formatDateTime.format(date, type) ⇒ any

Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11

ParamTypeDescription
dateany
typeanylocalInput, dateInput, timeInput,

Example

TO SECONDS formatDateTime.format("00:00:10", "") // 10
TO CASUAL formatDateTime.format("", "")
TO BEFORE
console.log(formatDateTime.format("Dec 11, 2012", "HHMMSS"))
console.log(formatDateTime.format("March 1, 2022", "dateInput")) 2022 - 03 - 01 < input type = "date" / >
        //  console.log(formatDateTime.format("March 1, 2022", "timeInput")) 00:00:00 <input type="time" step="1" />
          //  console.log(formatDateTime.format("March 1, 2022", "LL"))  March 1, 2002
         console.log(formatDateTime.format("March 1, 2022", "localInput")) 2022 - 03 - 01 T00: 00: 00 < input type = "datetime-local"
         step = "1" / >

formatDateTime.digitalToSeconds(string) ⇒ integer

Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11

ParamType
stringany

Example

digitalToSeconds(00:33:22) -> seconds

formatDateTime.formatDateToPost(stringInput) ⇒ date

Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11

ParamType
stringInputany

Example

formatDateToPost(stringInput)

formatDateTime.secondsString(seconds) ⇒ string

Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11

ParamType
secondsany

Example

secondsString(seconds)

formatDateTime.isBetween(start, end) ⇒ boolean

Good to use if you want to see a date is before another

Kind: instance method of FormatDateTime
Returns: boolean - or object
Date: 2022-01-20
Author: lezzles11 :) www.github.com/lezzles11

ParamType
startany
endany

formatDateTime.secondsToDigital(seconds) ⇒ any

console.log(formatDateTime.secondsToDigital(23423)) 06: 30: 23

Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11

ParamType
secondsany

formatDateTime.getDate(getDate, option) ⇒ any

getDate(date, options)

Kind: instance method of FormatDateTime
Date: 2022-01-13
Author: lezzles11 :) www.github.com/lezzles11

ParamType
getDateany
optionany

Create

let march2 = formatDateTime.getDaysAgo(2) // March 2, 2022
1.14.9

2 years ago

1.14.8

2 years ago

1.14.5

2 years ago

1.14.4

2 years ago

1.14.3

2 years ago

1.14.7

2 years ago

1.14.6

2 years ago

1.14.2

2 years ago

1.14.1

2 years ago

1.14.0

2 years ago

1.13.4

2 years ago

1.13.2

2 years ago

1.13.1

2 years ago

1.13.0

2 years ago

1.12.0

2 years ago

1.11.0

2 years ago

1.10.0

2 years ago

1.9.0

2 years ago

1.8.0

2 years ago

1.1.1

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago