Huge Huang![]()
use AOP to alter gallery-torelativetime logic so we can support absolute/relative time format with given relativeDelta
<script src="http://yui.yahooapis.com/3.5.0/build/yui/yui-min.js"></script><!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://yui.yahooapis.com/3.5.0/build/yui/yui-min.js"></script>
<title>gallery-time-format showcase</title>
</head>
<body>
<script type="text/javascript">
YUI({ gallery: 'gallery-2012.08.01-13-16' }).use('gallery-time-format', function (Y) {
var to = new Date('2012-02-12T11:00:00Z'),
from;
from = new Date('2012-02-12T14:00:00Z');
console.log(Y.DataType.Date.format(to, { from: from, relativeDelta: 3*60*60 }), 'about 3 hours before');
// time different is bigger than relativeDelta
from = new Date('2012-02-12T17:00:00Z');
console.log(Y.DataType.Date.format(to, { from: from, relativeDelta: 3*60*60 }), '2012-02-12');
// 1 hour earlier
from = new Date('2012-02-12T10:00:00Z');
console.log(Y.DataType.Date.format(to, { from: from, relativeDelta: 3*60*60 }), 'about an hour ahead');
// support different format
from = new Date('2012-02-12T17:00:00Z');
console.log(Y.DataType.Date.format(to, { from: from, relativeDelta: 3*60*60, format: '%x' }), '02/12/12');
})
</script>
</body>
</html>
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info