Skip to content

Instantly share code, notes, and snippets.

@adekbadek
Last active March 15, 2016 19:57
Show Gist options
  • Save adekbadek/23acf6bca7761e1441f9 to your computer and use it in GitHub Desktop.
Save adekbadek/23acf6bca7761e1441f9 to your computer and use it in GitHub Desktop.
// in each paragraph, add a 24h-formatted time and convert from EST to Central Europe time.
// BEWARE between Mar 13 and Mar 26 USA already change to DST, while Poland still waits. Next funkyzeit in Nov.
$('p').each(function(){
var match = $(this).html().match(/([\w]*):([\w]*) ([\w]*)/)
if(match != null && match.length >= 0){
var h = match[1]
var m = match[2]
var ap = match[3]
if((ap == 'AM' || ap == 'am') && h == 12){
h = 00
}
if((ap == 'PM' || ap == 'pm') && h != 12){
h = parseInt(h) + 12
}
var format_24 = h + ":" + m
var warsaw_h = (parseInt(h) + 6)
if(warsaw_h > 24 || warsaw_h >= 24 && m>0){
var warsaw_time = "24:00 +" + (warsaw_h-24) + "h " + m + "m"
}else{
var warsaw_time = warsaw_h + ":" + m
}
$(this).html(
$(this).html().replace(/(PM|AM)/gi, '$1 ('+ format_24 +', in Warsaw: <b>'+warsaw_time+'</b>)')
)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment