From 8244aae227025150a77d6377caa52e0b7b0b5cbc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 21 Mar 2014 12:54:03 +0100 Subject: [PATCH 1/1] fnpjs: datetime --- src/fnpjs/datetime.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/fnpjs/datetime.js diff --git a/src/fnpjs/datetime.js b/src/fnpjs/datetime.js new file mode 100644 index 0000000..7ebee12 --- /dev/null +++ b/src/fnpjs/datetime.js @@ -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 -- 2.20.1