summaryrefslogtreecommitdiff
path: root/node_modules/locutus/php/datetime/date_parse.js
diff options
context:
space:
mode:
authorMarvin Borner2018-11-07 18:02:36 +0100
committerMarvin Borner2018-11-07 18:02:36 +0100
commit824a2d9f587ca017fc71b84d835e72f54f9c87c4 (patch)
tree765267ea4686f752aad1f69930cfee5680cc494a /node_modules/locutus/php/datetime/date_parse.js
parentfe75612e86b493a4e66c4e104e22658679cc014f (diff)
Began rewrite
Diffstat (limited to 'node_modules/locutus/php/datetime/date_parse.js')
-rw-r--r--node_modules/locutus/php/datetime/date_parse.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/node_modules/locutus/php/datetime/date_parse.js b/node_modules/locutus/php/datetime/date_parse.js
new file mode 100644
index 0000000..20df2bf
--- /dev/null
+++ b/node_modules/locutus/php/datetime/date_parse.js
@@ -0,0 +1,38 @@
+'use strict';
+
+module.exports = function date_parse(date) {
+ // eslint-disable-line camelcase
+ // discuss at: http://locutus.io/php/date_parse/
+ // original by: Brett Zamir (http://brett-zamir.me)
+ // example 1: date_parse('2006-12-12 10:00:00')
+ // returns 1: {year : 2006, month: 12, day: 12, hour: 10, minute: 0, second: 0, fraction: 0, is_localtime: false}
+
+ var strtotime = require('../datetime/strtotime');
+ var ts;
+
+ try {
+ ts = strtotime(date);
+ } catch (e) {
+ ts = false;
+ }
+
+ if (!ts) {
+ return false;
+ }
+
+ var dt = new Date(ts * 1000);
+
+ var retObj = {};
+
+ retObj.year = dt.getFullYear();
+ retObj.month = dt.getMonth() + 1;
+ retObj.day = dt.getDate();
+ retObj.hour = dt.getHours();
+ retObj.minute = dt.getMinutes();
+ retObj.second = dt.getSeconds();
+ retObj.fraction = parseFloat('0.' + dt.getMilliseconds());
+ retObj.is_localtime = dt.getTimezoneOffset() !== 0;
+
+ return retObj;
+};
+//# sourceMappingURL=date_parse.js.map \ No newline at end of file