JSFiddle - React, Tailwind, and code Playground

by JAAulde

JavaScript

( function( global )
{
  "use strict";
  
  var dayNameMap = {
      Sun: 'Sunday',
      Mon: 'Monday',
      Tue: 'Tuesday',
      Wed: 'Wednesday',
      Thu: 'Thursday',
      Fri: 'Friday',
      Sat: 'Saturday'
    },
    monthNameMap = {
      Jan: 'January',
      Feb: 'February',
      Mar: 'March',
      Apr: 'April',
      Jun: 'June',
      Jul: 'July',
      Aug: 'August',
      Sep: 'September',
      Oct: 'October',
      Nov: 'November',
      Dec: 'December'
    },
    parser = /@: ([a-z]{1,3}), ([0-9]+) ([a-z]{1,3}) ([0-9]+) ([0-9]+):([0-9]+):([0-9]+) -[0-9]+ Running:/ig,
    replacer = function( str, day, date, month, year, hour, minute, second )
    {
      var isPM;

      isPM = false;
  
      hour = parseInt( hour, 10 );
  
      if( hour > 11 )
      {
        hour -= 12;
        isPM = true;
      }
  
      if( hour === 0 )
      {
        hour = 12;
      }
   
      return ( [
        '@: ',
        ( typeof dayNameMap[day] !== 'undefined' ? dayNameMap[day] : day ),
        ', ',
        ( typeof monthNameMap[month] !== 'undefined' ? monthNameMap[month] : month ),
        ' ',
        date,
        ', ',
        year,
        ' at ',
        hour,
        ':',
        (  ( minute.length === 1 ? '0' : '' ) + minute ),
        ':',
        (  ( second.length === 1 ? '0' : '' ) + second ),
        ' ',
        ( isPM ? 'PM' : 'AM' ),
        ' Running:'
      ] ).join( '' );
    };
  
  global.jQuery.translateTimeAndDate = function( text )
  {
    return text.replace( parser, replacer );
  };
}( window ) );


var x = '#: 4362 @: Mon, 22 Aug 2011 23:59:59 -0400 Running: 0.4.9_Final\
#: 4363 @: Tue, 23 Aug 2011 00:00:09 -0400 Running: 0.4.9_Final';

document.write( $.translateTimeAndDate( x ) );