fnpjs: datetime
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 21 Mar 2014 11:54:03 +0000 (12:54 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 21 Mar 2014 11:54:03 +0000 (12:54 +0100)
src/fnpjs/datetime.js [new file with mode: 0644]

diff --git a/src/fnpjs/datetime.js b/src/fnpjs/datetime.js
new file mode 100644 (file)
index 0000000..7ebee12
--- /dev/null
@@ -0,0 +1,30 @@
+define(function() {
+    
+'use strict';
+
+var pad = function(number) {
+    if(number < 10) {
+        number = '0' + number;
+    }
+    return number;
+};
+
+var defaultFormat = '%d-%m-%y %H:%M:%S';
+
+return {
+    strfmt: function(datetime, format) {
+        format = format || defaultFormat;
+        return format
+            .replace('%d', pad(datetime.getDate()))
+            .replace('%m', pad((datetime.getMonth() + 1)))
+            .replace('%y', pad(datetime.getFullYear()))
+            .replace('%H', pad(datetime.getHours()))
+            .replace('%M', pad(datetime.getMinutes()))
+            .replace('%S', pad(datetime.getSeconds()));
+    },
+    currentStrfmt: function(format) {
+        return this.strfmt(new Date(), format);
+    }
+};
+
+});
\ No newline at end of file