@basichelpers/date
Advanced tools
Comparing version 0.0.1 to 0.0.2
63
index.ts
@@ -1,35 +0,34 @@ | ||
export default class date { | ||
/** | ||
* @param {date} payload | ||
* @param {string} format YYYY/MM/DD hh:mm:ss:SSS | ||
* @returns {string} | ||
*/ | ||
dateFormat (payload: Date, format: string = 'YYYY/MM/DD') { | ||
format = format.replace(/YYYY/g, payload.getFullYear().toString()) | ||
format = format.replace(/MM/g, ('0' + (payload.getMonth() + 1)).slice(-2)) | ||
format = format.replace(/DD/g, ('0' + payload.getDate()).slice(-2)) | ||
format = format.replace(/hh/g, ('0' + payload.getHours()).slice(-2)) | ||
format = format.replace(/mm/g, ('0' + payload.getMinutes()).slice(-2)) | ||
format = format.replace(/ss/g, ('0' + payload.getSeconds()).slice(-2)) | ||
format = format.replace( | ||
/SSS/g, | ||
('00' + payload.getMilliseconds()).slice(-3) | ||
) | ||
return format | ||
} | ||
/** | ||
* @param {date} payload | ||
* @param {string} format YYYY/MM/DD hh:mm:ss:SSS | ||
* @returns {string} | ||
*/ | ||
export function dateFormat (payload: Date, format: string = 'YYYY/MM/DD') { | ||
format = format.replace(/YYYY/g, payload.getFullYear().toString()) | ||
format = format.replace(/MM/g, ('0' + (payload.getMonth() + 1)).slice(-2)) | ||
format = format.replace(/DD/g, ('0' + payload.getDate()).slice(-2)) | ||
format = format.replace(/hh/g, ('0' + payload.getHours()).slice(-2)) | ||
format = format.replace(/mm/g, ('0' + payload.getMinutes()).slice(-2)) | ||
format = format.replace(/ss/g, ('0' + payload.getSeconds()).slice(-2)) | ||
format = format.replace(/SSS/g, ('00' + payload.getMilliseconds()).slice(-3)) | ||
return format | ||
} | ||
/** | ||
* @param {string} payload 2021/12/31 | ||
* @param {string} format | ||
* @param {string} time 12:00 | ||
* @returns {date} | ||
*/ | ||
stringtoDate (date: string, st: string, time: string = ''): Date { | ||
const will: any = new RegExp(st, 'g') | ||
let willdate = date.replace(will, '/') | ||
if (time) { | ||
willdate = willdate + ' ' + time + ':00' | ||
} | ||
return new Date(willdate) | ||
/** | ||
* @param {string} payload 2021/12/31 | ||
* @param {string} format | ||
* @param {string} time 12:00 | ||
* @returns {date} | ||
*/ | ||
export function stringtoDate ( | ||
date: string, | ||
st: string, | ||
time: string = '' | ||
): Date { | ||
const will: any = new RegExp(st, 'g') | ||
let willdate = date.replace(will, '/') | ||
if (time) { | ||
willdate = willdate + ' ' + time + ':00' | ||
} | ||
return new Date(willdate) | ||
} |
{ | ||
"name": "@basichelpers/date", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "```bash import { dateFormat, stringtoDate } from '@basichelpers/date'", | ||
"main": "index.ts", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
@@ -10,7 +10,10 @@ "test": "echo \"Error: no test specified\" && exit 1", | ||
}, | ||
"author": "", | ||
"author": "91nakashima", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"typescript": "^4.5.4" | ||
} | ||
} |
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
14002
5
160
1
1
+ Addedtypescript@^4.5.4
+ Addedtypescript@4.9.5(transitive)