diff options
author | Joel Kronqvist <joel.h.kronqvist@gmail.com> | 2022-02-09 22:24:26 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.h.kronqvist@gmail.com> | 2022-02-09 22:24:26 +0200 |
commit | b270c4475ca6ed61784ed8368ab42fea3dc528e5 (patch) | |
tree | 2b895a8b5d7b0a8ed0c8eea37278e3ab10e048ba /Functions/dateFuncs.js | |
parent | 41b36e79f32e6a9efffe1c0100ddc339dbaaeabb (diff) | |
download | LYLLRuoka-b270c4475ca6ed61784ed8368ab42fea3dc528e5.tar.gz LYLLRuoka-b270c4475ca6ed61784ed8368ab42fea3dc528e5.zip |
Merged all functions from the JoelHMikael/funcs
Necessary, because we don't want to complicate our update script & its anyways better like this. They weren't any complicated functions.
Diffstat (limited to 'Functions/dateFuncs.js')
-rw-r--r-- | Functions/dateFuncs.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Functions/dateFuncs.js b/Functions/dateFuncs.js new file mode 100644 index 0000000..10c4250 --- /dev/null +++ b/Functions/dateFuncs.js @@ -0,0 +1,23 @@ +// s: DD-MM-YYYY, return: Date +function stringToDate(s) { + const date = s.split("-"); + return new Date(`${date[2].padStart(4, "0")}-${date[1].padStart(2, "0")}-${date[0].padStart(2, "0")}`); +} + +const isBetweenDates = (date, date1, date2) => { + date = approxDate(date); + date1 = approxDate(date1); + date2 = approxDate(date2); + return ((date.getTime() >= date1.getTime()) + && (date.getTime() <= date2.getTime())); +}; + +function approxDate(d) +{ + return new Date(`${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, "0")}-${d.getDate().toString().padStart(2, "0")}`); +} + +module.exports = { + fromString: stringToDate, + between: isBetweenDates +}
\ No newline at end of file |