The Gallery is deprecated. No new Gallery components may be submitted, and modifying existing components is disabled. For more information please read the Gallery Deprecation blog post. This is a static snapshot of the Gallery for archive purposes.
Created: 07/31/12
Last CDN Push: 08/1/12
Build Tag: gallery-2012.08.01-13-16
Project: YUI 3
License: YUI BSD
YUI Version: 3.5.0
Free for use.
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>
All code on this site is licensed under the BSD License unless stated otherwise.