(function (){
var tz='';
try { tz=Intl.DateTimeFormat().resolvedOptions().timeZone||''; } catch(e){}
var USE_12H=/^America\//.test(tz);
if(USE_12H){ try { document.documentElement.classList.add('ds-ampm'); } catch(e){}}
var FORMATS={
'datetime':   { day: 'numeric', month: 'long', year: 'numeric' },
'date-full':  { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' },
'date-short': { day: 'numeric', month: 'short' },
'time':       USE_12H
? { hour: 'numeric', minute: '2-digit', hour12: true }
: { hour: '2-digit', minute: '2-digit', hour12: false }};
var DATETIME_TIME={ hour: 'numeric', minute: '2-digit', hour12: USE_12H };
function fmt(d, opts){
return new Intl.DateTimeFormat(undefined, opts).format(d);
}
function render(d, kind){
if(kind==='datetime'){
return fmt(d, FORMATS.datetime) + ', ' + fmt(d, DATETIME_TIME);
}
if(kind==='time'){
var t=fmt(d, FORMATS.time);
return USE_12H ? t.replace(/\s+/g, '').toLowerCase():t;
}
return fmt(d, FORMATS[ kind ]||FORMATS.time);
}
function run(){
var els=document.querySelectorAll('time.ds-localtime[datetime]');
for(var i=0; i < els.length; i++){
var el=els[ i ];
var d=new Date(el.getAttribute('datetime') );
if(isNaN(d.getTime()) ){ continue; }
try {
el.textContent=render(d, el.getAttribute('data-fmt') );
} catch(e){  }}
}
if(document.readyState==='loading'){
document.addEventListener('DOMContentLoaded', run);
}else{
run();
}})();