Recent Changes - Search:

go to the forum

Contents

Site

Help

« jun 2022 · oct 2022 »

    add a calendar item

    JavaScript / Fix Dates

    JavaScript.FixDates History

    Hide minor edits - Show changes to markup

    2013-03-03 12:19 [UTC-7] by Blue Hell -
    Added line 1:
    Deleted lines 2-3:

    <script type='text/javascript' src='http://electro-music.com/wiki/pub/common.js'></script>

    2013-03-03 12:08 [UTC-7] by Blue Hell -
    2013-03-03 11:48 [UTC-7] by Blue Hell -
    Deleted line 0:
    Added lines 2-3:

    <script type='text/javascript' src='http://electro-music.com/wiki/pub/common.js'></script>

    2013-03-03 11:33 [UTC-7] by Blue Hell -
    Added line 1:
    Deleted lines 2-3:

    <script type='text/javascript' src='http://electro-music.com/wiki/pub/common.js'></script>

    2013-03-03 11:21 [UTC-7] by Blue Hell -
    Deleted line 0:
    Added lines 2-4:

    <script type='text/javascript' src='http://electro-music.com/wiki/pub/common.js'></script>

    Added line 8:
    2013-03-03 11:19 [UTC-7] by Blue Hell -
    Added line 1:
    Deleted lines 2-4:

    <script type='text/javascript' src='http://electro-music.com/wiki/pub/common.js'></script>

    Deleted line 5:
    2013-03-02 16:08 [UTC-7] by Blue Hell -
    2013-03-02 15:53 [UTC-7] by Blue Hell -
    Deleted lines 5-109:
      function parseISO8601String( dateString) 
      {
        var timebits = 
          /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2})(?::([0-9]*)(\.[0-9]*)?)?(?:([+-])([0-9]{2})([0-9]{2}))?/;
        var m = timebits.exec( dateString);
        var resultDate;
        if( m) 
        {
          var utcdate = 
            Date.UTC(
              parseInt( m[ 1]),
              parseInt( m[ 2]) - 1,                       // months are zero-offset (!)
              parseInt( m[ 3]),
              parseInt( m[ 4]), parseInt( m[ 5]),         // hh:mm
              ( m[ 6] && parseInt( m[ 6]) || 0),          // optional seconds
              ( m[ 7] && parseFloat( m[ 7]) * 1000) || 0  // optional fraction
            );
    
          // utcdate is milliseconds since the epoch
    
          if( m[ 9] && m[ 10]) 
          {
            var offsetMinutes = parseInt(m[9]) * 60 + parseInt( m[ 10]);
            utcdate += ( m[ 8] === '+' ? -1 : +1) * offsetMinutes * 60000;
          }
          resultDate = new Date( utcdate);
        } 
        else 
        {
          resultDate = null;
        }
        return resultDate;
      }
    
    
      function fix_digits( num)
      {
        if( num < 10)
          return '0' + num;
        else
          return num;
      }
    
      function replace_dates()
      { 
        var dates = document.getElementsByClassName( "xldt");
        var stamp;
        var parts;
        var date;
        var time;
        var time_zone;
        var year;
        var month;
        var day;
        var hour;
        var minute;
        var tz;
        var len;
        var dt;
        var dts;
        var tzsign;
        var tzdata;
        var now;
    
        for( var i = 0; i < dates.length; i++) 
        {
          stamp     = dates[ i].innerHTML;
          parts     = stamp.split( ' ');
          date      = parts[ 0];
          time      = parts[ 1];
          time_zone = parts[ 3]; 
          parts     = date.split( '-');
          year      = parts[ 0];
          month     = parts[ 1];
          day       = parts[ 2];
          parts     = time.split( ':');
          hour      = parts[ 0];
          minute    = parts[ 1];
          tz        = time_zone.substr( 4);
          len       = tz.length;
          tz        = tz.substr( 0, len - 1);
          tzsign    = tz.substr( 0, 1);
          tzdata    = tz.substr( 1, 2);
    
          if( tzdata.length < 2)
          {
            tzdata = '0' + tzdata;
          }
    
          tz        = tzsign + tzdata + '00';
          dts       = year + ' + month + ' + day + 'T' + hour + ':' + minute + ':00.000' + tz;
          dt        = new Date( parseISO8601String( dts));
    
          year      = dt.getFullYear();
          month     = fix_digits( dt.getMonth() + 1);
          day       = fix_digits( dt.getDate());
          hour      = fix_digits( dt.getHours());
          minute    = fix_digits( dt.getMinutes());
          dt        = year + ' + month + ' + day + ' ' + hour + ':' + minute;
    
          dates[ i].innerHTML = dt;
        }
      }
    
    2013-02-28 20:47 [UTC-7] by Blue Hell -
    Changed lines 9-10 from:
        var timebits = /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2})(?::([0-9]*)(\.[0-9]*)?)?(?:([+-])([0-9]{2})([0-9]{2}))?/;
    
    to:
        var timebits = 
          /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2})(?::([0-9]*)(\.[0-9]*)?)?(?:([+-])([0-9]{2})([0-9]{2}))?/;
    
    Deleted line 97:
       // dt        = new Date( Date.parse( dts));
    
    2013-02-28 20:42 [UTC-7] by Blue Hell -
    Changed line 7 from:
      function fix_digits( num)
    
    to:
      function parseISO8601String( dateString) 
    
    Changed lines 9-36 from:
        if( num < 10)
          return '0' + num;
        else
          return num;
      }
    
      function replace_dates()
      { 
        var dates = document.getElementsByClassName( "xldt");
        var stamp;
        var parts;
        var date;
        var time;
        var time_zone;
        var year;
        var month;
        var day;
        var hour;
        var minute;
        var tz;
        var len;
        var dt;
        var dts;
        var tzsign;
        var tzdata;
        var now;
    
        for( var i = 0; i < dates.length; i++) 
    
    to:
        var timebits = /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2})(?::([0-9]*)(\.[0-9]*)?)?(?:([+-])([0-9]{2})([0-9]{2}))?/;
        var m = timebits.exec( dateString);
        var resultDate;
        if( m) 
    
    Changed lines 14-30 from:
          stamp     = dates[ i].innerHTML;
          parts     = stamp.split( ' ');
          date      = parts[ 0];
          time      = parts[ 1];
          time_zone = parts[ 3]; 
          parts     = date.split( '-');
          year      = parts[ 0];
          month     = parts[ 1];
          day       = parts[ 2];
          parts     = time.split( ':');
          hour      = parts[ 0];
          minute    = parts[ 1];
          tz        = time_zone.substr( 4);
          len       = tz.length;
          tz        = tz.substr( 0, len - 1);
          tzsign    = tz.substr( 0, 1);
          tzdata    = tz.substr( 1, 2);
    
    to:
          var utcdate = 
            Date.UTC(
              parseInt( m[ 1]),
              parseInt( m[ 2]) - 1,                       // months are zero-offset (!)
              parseInt( m[ 3]),
              parseInt( m[ 4]), parseInt( m[ 5]),         // hh:mm
              ( m[ 6] && parseInt( m[ 6]) || 0),          // optional seconds
              ( m[ 7] && parseFloat( m[ 7]) * 1000) || 0  // optional fraction
            );
    
    Changed lines 24-26 from:
          if( tzdata.length < 2)
    
    to:
          // utcdate is milliseconds since the epoch
    
          if( m[ 9] && m[ 10]) 
    
    Changed lines 28-29 from:
            tzdata = '0' + tzdata;
    
    to:
            var offsetMinutes = parseInt(m[9]) * 60 + parseInt( m[ 10]);
            utcdate += ( m[ 8] === '+' ? -1 : +1) * offsetMinutes * 60000;
    
    Changed lines 31-44 from:
          tz        = tzsign + tzdata + '00';
          dts       = year + ' + month + ' + day + 'T' + hour + ':' + minute + ':00.000' + tz;
          dt        = new Date( Date.parse( dts));
    
          year      = dt.getFullYear();
          month     = fix_digits( dt.getMonth() + 1);
          day       = fix_digits( dt.getDate());
          hour      = fix_digits( dt.getHours());
          minute    = fix_digits( dt.getMinutes());
          dt        = year + ' + month + ' + day + ' ' + hour + ':' + minute;
    
          dates[ i].innerHTML = dt;
        }
    
    to:
          resultDate = new Date( utcdate);
        } 
        else 
        {
          resultDate = null;
        }
        return resultDate;
      }
    
    
      function fix_digits( num)
      {
        if( num < 10)
          return '0' + num;
        else
          return num;
      }
    
      function replace_dates()
      { 
        var dates = document.getElementsByClassName( "xldt");
        var stamp;
        var parts;
        var date;
        var time;
        var time_zone;
        var year;
        var month;
        var day;
        var hour;
        var minute;
        var tz;
        var len;
        var dt;
        var dts;
        var tzsign;
        var tzdata;
        var now;
    
        for( var i = 0; i < dates.length; i++) 
        {
          stamp     = dates[ i].innerHTML;
          parts     = stamp.split( ' ');
          date      = parts[ 0];
          time      = parts[ 1];
          time_zone = parts[ 3]; 
          parts     = date.split( '-');
          year      = parts[ 0];
          month     = parts[ 1];
          day       = parts[ 2];
          parts     = time.split( ':');
          hour      = parts[ 0];
          minute    = parts[ 1];
          tz        = time_zone.substr( 4);
          len       = tz.length;
          tz        = tz.substr( 0, len - 1);
          tzsign    = tz.substr( 0, 1);
          tzdata    = tz.substr( 1, 2);
    
          if( tzdata.length < 2)
          {
            tzdata = '0' + tzdata;
          }
    
          tz        = tzsign + tzdata + '00';
          dts       = year + ' + month + ' + day + 'T' + hour + ':' + minute + ':00.000' + tz;
       // dt        = new Date( Date.parse( dts));
          dt        = new Date( parseISO8601String( dts));
    
    2013-02-28 20:27 [UTC-7] by Blue Hell -
    Changed line 62 from:
          dts       = year + '/' + month + '/' + day + 'T' + hour + ':' + minute + ':00.000' + tz;
    
    to:
          dts       = year + ' + month + ' + day + 'T' + hour + ':' + minute + ':00.000' + tz;
    
    2013-02-28 20:26 [UTC-7] by Blue Hell -
    Changed line 62 from:
          dts       = year + ' + month + ' + day + 'T' + hour + ':' + minute + ':00.000' + tz;
    
    to:
          dts       = year + '/' + month + '/' + day + 'T' + hour + ':' + minute + ':00.000' + tz;
    
    Changed line 70 from:
          dt        = year + '/' + month + '/' + day + ' ' + hour + ':' + minute;
    
    to:
          dt        = year + ' + month + ' + day + ' ' + hour + ':' + minute;
    
    2013-02-28 20:25 [UTC-7] by Blue Hell -
    Changed line 70 from:
          dt        = year + ' + month + ' + day + ' ' + hour + ':' + minute;
    
    to:
          dt        = year + '/' + month + '/' + day + ' ' + hour + ':' + minute;
    
    2013-02-28 20:03 [UTC-7] by Blue Hell -
    Changed line 17 from:
        var dates = document.getElementsByClass( "xldt");
    
    to:
        var dates = document.getElementsByClassName( "xldt");
    
    2013-02-28 20:00 [UTC-7] by Blue Hell -
    Changed line 17 from:
        var dates = document.getElementsByName( "xldt");
    
    to:
        var dates = document.getElementsByClass( "xldt");
    
    2013-02-28 19:23 [UTC-7] by Blue Hell -
    Changed lines 43-56 from:
          if( 'time_zone' in window)
    
    to:
          parts     = date.split( '-');
          year      = parts[ 0];
          month     = parts[ 1];
          day       = parts[ 2];
          parts     = time.split( ':');
          hour      = parts[ 0];
          minute    = parts[ 1];
          tz        = time_zone.substr( 4);
          len       = tz.length;
          tz        = tz.substr( 0, len - 1);
          tzsign    = tz.substr( 0, 1);
          tzdata    = tz.substr( 1, 2);
    
          if( tzdata.length < 2)
    
    Changed lines 58-69 from:
            parts     = date.split( '-');
            year      = parts[ 0];
            month     = parts[ 1];
            day       = parts[ 2];
            parts     = time.split( ':');
            hour      = parts[ 0];
            minute    = parts[ 1];
            tz        = time_zone.substr( 4);
            len       = tz.length;
            tz        = tz.substr( 0, len - 1);
            tzsign    = tz.substr( 0, 1);
            tzdata    = tz.substr( 1, 2);
    
    to:
            tzdata = '0' + tzdata;
          }
    
    Changed lines 61-64 from:
            if( tzdata.length < 2)
            {
              tzdata = '0' + tzdata;
            }
    
    to:
          tz        = tzsign + tzdata + '00';
          dts       = year + ' + month + ' + day + 'T' + hour + ':' + minute + ':00.000' + tz;
          dt        = new Date( Date.parse( dts));
    
    Changed lines 65-77 from:
            tz        = tzsign + tzdata + '00';
            dts       = year + ' + month + ' + day + 'T' + hour + ':' + minute + ':00.000' + tz;
            dt        = new Date( Date.parse( dts));
    
            year      = dt.getFullYear();
            month     = fix_digits( dt.getMonth() + 1);
            day       = fix_digits( dt.getDate());
            hour      = fix_digits( dt.getHours());
            minute    = fix_digits( dt.getMinutes());
            dt        = year + ' + month + ' + day + ' ' + hour + ':' + minute;
    
            dates[ i].innerHTML = dt;
          }
    
    to:
          year      = dt.getFullYear();
          month     = fix_digits( dt.getMonth() + 1);
          day       = fix_digits( dt.getDate());
          hour      = fix_digits( dt.getHours());
          minute    = fix_digits( dt.getMinutes());
          dt        = year + ' + month + ' + day + ' ' + hour + ':' + minute;
    
          dates[ i].innerHTML = dt;
    
    2013-02-28 19:20 [UTC-7] by Blue Hell -
    Changed lines 43-56 from:
          parts     = date.split( '-');
          year      = parts[ 0];
          month     = parts[ 1];
          day       = parts[ 2];
          parts     = time.split( ':');
          hour      = parts[ 0];
          minute    = parts[ 1];
          tz        = time_zone.substr( 4);
          len       = tz.length;
          tz        = tz.substr( 0, len - 1);
          tzsign    = tz.substr( 0, 1);
          tzdata    = tz.substr( 1, 2);
    
          if( tzdata.length < 2)
    
    to:
          if( 'time_zone' in window)
    
    Changed lines 45-46 from:
            tzdata = '0' + tzdata;
          }
    
    to:
            parts     = date.split( '-');
            year      = parts[ 0];
            month     = parts[ 1];
            day       = parts[ 2];
            parts     = time.split( ':');
            hour      = parts[ 0];
            minute    = parts[ 1];
            tz        = time_zone.substr( 4);
            len       = tz.length;
            tz        = tz.substr( 0, len - 1);
            tzsign    = tz.substr( 0, 1);
            tzdata    = tz.substr( 1, 2);
    
    Changed lines 58-60 from:
          tz        = tzsign + tzdata + '00';
          dts       = year + ' + month + ' + day + 'T' + hour + ':' + minute + ':00.000' + tz;
          dt        = new Date( Date.parse( dts));
    
    to:
            if( tzdata.length < 2)
            {
              tzdata = '0' + tzdata;
            }
    
    Changed lines 63-70 from:
          year      = dt.getFullYear();
          month     = fix_digits( dt.getMonth() + 1);
          day       = fix_digits( dt.getDate());
          hour      = fix_digits( dt.getHours());
          minute    = fix_digits( dt.getMinutes());
          dt        = year + ' + month + ' + day + ' ' + hour + ':' + minute;
    
          dates[ i].innerHTML = dt;
    
    to:
            tz        = tzsign + tzdata + '00';
            dts       = year + ' + month + ' + day + 'T' + hour + ':' + minute + ':00.000' + tz;
            dt        = new Date( Date.parse( dts));
    
            year      = dt.getFullYear();
            month     = fix_digits( dt.getMonth() + 1);
            day       = fix_digits( dt.getDate());
            hour      = fix_digits( dt.getHours());
            minute    = fix_digits( dt.getMinutes());
            dt        = year + ' + month + ' + day + ' ' + hour + ':' + minute;
    
            dates[ i].innerHTML = dt;
          }
    
    2013-02-28 18:48 [UTC-7] by Blue Hell -
    Added lines 1-79:

    (:html:)

    <script type='text/javascript' src='http://electro-music.com/wiki/pub/common.js'></script>

    <script type="text/javascript">

      function fix_digits( num)
      {
        if( num < 10)
          return '0' + num;
        else
          return num;
      }
    
      function replace_dates()
      { 
        var dates = document.getElementsByName( "xldt");
        var stamp;
        var parts;
        var date;
        var time;
        var time_zone;
        var year;
        var month;
        var day;
        var hour;
        var minute;
        var tz;
        var len;
        var dt;
        var dts;
        var tzsign;
        var tzdata;
        var now;
    
        for( var i = 0; i < dates.length; i++) 
        {
          stamp     = dates[ i].innerHTML;
          parts     = stamp.split( ' ');
          date      = parts[ 0];
          time      = parts[ 1];
          time_zone = parts[ 3]; 
          parts     = date.split( '-');
          year      = parts[ 0];
          month     = parts[ 1];
          day       = parts[ 2];
          parts     = time.split( ':');
          hour      = parts[ 0];
          minute    = parts[ 1];
          tz        = time_zone.substr( 4);
          len       = tz.length;
          tz        = tz.substr( 0, len - 1);
          tzsign    = tz.substr( 0, 1);
          tzdata    = tz.substr( 1, 2);
    
          if( tzdata.length < 2)
          {
            tzdata = '0' + tzdata;
          }
    
          tz        = tzsign + tzdata + '00';
          dts       = year + ' + month + ' + day + 'T' + hour + ':' + minute + ':00.000' + tz;
          dt        = new Date( Date.parse( dts));
    
          year      = dt.getFullYear();
          month     = fix_digits( dt.getMonth() + 1);
          day       = fix_digits( dt.getDate());
          hour      = fix_digits( dt.getHours());
          minute    = fix_digits( dt.getMinutes());
          dt        = year + ' + month + ' + day + ' ' + hour + ':' + minute;
    
          dates[ i].innerHTML = dt;
        }
      }
    
      addLoadEvent( replace_dates);
    

    </script>

    (:htmlend:)

    Edit - History - Print - Recent Changes - Search Page last modified on 2013-03-03 12:19 [UTC-7] - 693 views