timeSolver.js
A small library for manipulating, validating and formatting JavaScript date object. Futhermore, it can helps you log your execution time by using timelook.
Current Version : v1.2.0
Getting Start
Installation
Install via npm or download source file directly
- npm
npm install timesolver
- source
https://github.com/sean1093/timeSolver/tree/master/src
Usage
You need to use timeSolver object to manipulate JavaScript date object.
Include timeSolver
, You can use global object in your page.
You also can use via require
.
const timeSolver = ;
For example, if you want to get datetime string with format "YYYYMMDD", you need to do by following:
const dateString = timeSolver;
Method
Add and Subtract
You can use this basic manipulate on date, add or subtract, by different time unit(type)
/** * Add time by time unit * * @param {date/string} [date] standard JavaScript Date object or date string * @param * @param * @return */const afterAdd = timeSolver; /** * Subtract time by time unit * * @param {date/string} [date] standard JavaScript Date object or date string * @param * @param * @return */const afterSubtract = timeSolver;
Equal
/** * Check whether two dates equals or not * * @param {date/string} [date1] standard JavaScript Date object or date string * @param {date/string} [date2] standard JavaScript Date object or date string * @return */const result = timeSolver;
After
/** * Check whether date1 after date2 or not * * @param {date/string} [date1] standard JavaScript Date object or date string * @param {date/string} [date2] standard JavaScript Date object or date string * @return */const result = timeSolver;
After Today
/** * Check whether date after today or not * * @param {date/string} [date] standard JavaScript Date object or date string * @return */const result = timeSolver;
Before
/** * Check whether date1 before date2 or not * * @param {date/string} [date1] standard JavaScript Date object or date string * @param {date/string} [date2] standard JavaScript Date object or date string * @return */const result = timeSolver;
Before Today
/** * Check whether date before today or not * * @param {date/string} [date] standard JavaScript Date object or date string * @return */const result = timeSolver;
Between
/** * Count time by time unit between two date * * @param {date/string} [date1] standard JavaScript Date object or date string * @param {date/string} [date2] standard JavaScript Date object or date string * @param * @return */const result = timeSolver;
Get Date String
/** * Get date time string by different format * * @param {date/string} [date] standard JavaScript Date object or date string * @param * @return */const dateString = timeSolver;
Get Week and Month
Get date's weekday or month name, it will return abbr. or full name by different method
const result1 = timeSolver;const result2 = timeSolver;const result3 = timeSolver;const result4 = timeSolver;
isValid
/** * Check whether date string is valid or not and return true/ false if dateString valid or not * * @param * @param * @return */const result = timeSolver;
getQuarterByMonth
/** * Get quarter by give month * * @param * @return */const quarter = timeSolver;
getFirstMonthByQuarter
/** * Get quarter's first month string by give quarter * * @param * @return */const firstMonth = timeSolver;
timeSolver time unit
-
time unit parameter abbr Millisecond "MILLISECOND" "mill" Second "SECOND" "s" Minute "MINUTE" "min" Hour "HOUR" "h" Day "DAY" "d" Month "MONTH" "m" Year "YEAR" "y"
timeSolver string format
-
format "YYYY" "YYYYMM" "YYYYMMDD" "MMDDYYYY" "HH:MM:SS" "HH:MM:SSS" "YYYY/MM/DD" "YYYY/MM/DD HH:MM:SS" "YYYY/MM/DD HH:MM:SS.SSS" "YYYY-MM-DD" "YYYY-MM-DD HH:MM:SS" "YYYY-MM-DD HH:MM:SS.SSS" "YYYY.MM.DD" "YYYY.MM.DD HH:MM:SS" "YYYY.MM.DD HH:MM:SS.SSS" "MM/DD/YYYY" "MM/DD/YYYY HH:MM:SS" "MM/DD/YYYY HH:MM:SS.SSS" "MM-DD-YYYY" "MM-DD-YYYY HH:MM:SS" "MM-DD-YYYY HH:MM:SS.SSS" "MM.DD.YYYY" "MM.DD.YYYY HH:MM:SS" "MM.DD.YYYY HH:MM:SS.SSS"
timeSolver valid format
-
format "YYYY/MM/DD" "YYYY-MM-DD" "YYYY.MM.DD" "YYYY/MM/DD HH:MM:SS" "YYYY-MM-DD HH:MM:SS" "YYYY.MM.DD HH:MM:SS"
timeLook
It can helps you log your execution time by using timeLook
- start timeLook
timeSolver;
- set your break point with label text
timeSolver;...timeSolver;......
- see your time log report
timeSolver;
For example, it will print on your browser console.
It will shows every execution time between your two break point, and mark the bottleneck with red color(Chrome Console).
License
MIT
Update log
- 1.2.0 (20180408)
- Add unit-test
- New feature: getQuarterByMonth and getFirstMonthByQuarter
- 1.1.1 (20180401)
- Add to npm
- 1.1.1 (20170718)
- Enhance function: isValid(), add three timestamp format
- 1.1.0 (20170614)
- New feature: timeLook, helps you log your execution time
- 1.0.7 (20170613)
- Bug fix: YYYYMMDD: 2017613 -> 20170613
- 1.0.6 (20170110)
- Add some new feature
- Add minify version
- 1.0.5 (20160813)
- Module load compatibility
- 1.0.4 (20160614)
- Bug fix
- 1.0.3 (20160425)
- Restructure
- 1.0.2
- Bug fix: between()
- 1.0.1
- Add new function: isValid()