aboutsummaryrefslogtreecommitdiffstats
path: root/libly.js
diff options
context:
space:
mode:
authoranekos2008-12-07 04:25:41 +0000
committeranekos2008-12-07 04:25:41 +0000
commit8e94121e416db446d971c4e4fccd5784959cce6b (patch)
tree969e07f18d3c6b5bf9b2cb0ede5ad638ffe0d511 /libly.js
parenta6fa63f4a60074b5fc133e123ad97f0a66c1b550 (diff)
downloadvimperator-plugins-8e94121e416db446d971c4e4fccd5784959cce6b.tar.bz2
$U.dateFormat の書式指定を実装
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@26036 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'libly.js')
-rw-r--r--libly.js33
1 files changed, 17 insertions, 16 deletions
diff --git a/libly.js b/libly.js
index 5878e9a..09bce6e 100644
--- a/libly.js
+++ b/libly.js
@@ -37,9 +37,9 @@ lib.$U = {//{{{
}
},
extend: function(dst, src) {
- for (let prop in src)
- dst[prop] = src[prop];
- return dst;
+ for (let prop in src)
+ dst[prop] = src[prop];
+ return dst;
},
A: function(hash, iter) {
var ret = [];
@@ -86,19 +86,20 @@ lib.$U = {//{{{
return link.href;
},
dateFormat: function(dtm, fmt) {
- var y = dtm.getFullYear();
- var M = dtm.getMonth() + 1;
- var d = dtm.getDay();
- var h = dtm.getHours();
- var m = dtm.getMinutes();
- var s = dtm.getSeconds();
-
- if (M < 10) M = '0' + M;
- if (d < 10) d = '0' + d;
- if (h < 10) h = '0' + h;
- if (m < 10) m = '0' + m;
- if (s < 10) s = '0' + s;
- return y + '/' + M + '/' + d + ' ' + h + ':' + m + ':' + s;
+ var d = {
+ y: dtm.getFullYear(),
+ M: dtm.getMonth() + 1,
+ d: dtm.getDay(),
+ h: dtm.getHours(),
+ m: dtm.getMinutes(),
+ s: dtm.getSeconds(),
+ '%': '%'
+ };
+ for (let [n, v] in Iterator(d)) {
+ if (v < 10)
+ d[n] = '0' + v;
+ }
+ return (fmt || '%y/%M/%d %h:%m:%s').replace(/%([yMdhms%])/g, function (_, n) d[n]);
},
readDirectory: function(path, filter, func) {
var d = io.getFile(path);