JSFiddle - React, Tailwind, and code Playground

by Gabriele Petrioli

JavaScript

var hash = '0847';//parent.location.hash;
    
    var minIncrement = 15; // how many minutes to increase
    
    // first we split the time in hours and mins
    var hours = parseInt(hash.substring(0, 2),10); // get hours (first 2 chars)
    var mins = parseInt(hash.substring(2, 4),10); // get mins (last 2 chars)
    
    // add the new minutes, and enforce it to fit 60 min hours 
    var newMins = (mins + minIncrement )%60; 
    // check if the added mins changed thehour 
    var newHours = Math.floor( (mins + minIncrement ) / 60 );
    
    // create the new time string (check if hours exceed 24 and restart it
    // first we create the hour string
    var endTime = ('0' + ((hours+newHours)%24).toString()).substr(-2);
    // then we add the min string
    endTime += ('0'+ newMins.toString()).substr(-2);

alert('From: ' + hash + '\nTo: ' + endTime);