<commit_before>OFFSET = 0;

function getLocation(callback) {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(callback);
    } else {
        callback(false);
    }
}

function calculateOffset(position) {
    var fraction = position.coords.longitude / 180.0;
    // milliseconds * seconds * minutes * hours
    var multiplicand = 1000 * 60 * 60 * 12;
    var milliseconds = fraction * multiplicand;
    return milliseconds;
}

function pad(n) {
    return (n < 10) ? ("0" + n) : n;
}

function formatDate(date) {
    return pad(date.getUTCHours()) + ':' + pad(date.getUTCMinutes()) + ':' + pad(date.getUTCSeconds());
}

function formatDelta(ms) {
    var date = new Date(ms);
    return formatDate(date);
}

function displayOffset(position) {
    var milliseconds = calculateOffset(position);
    OFFSET = milliseconds;
    var message;
    if (milliseconds > 0.0) {
        message = formatDelta(milliseconds) + ' ahead of UTC';
    }
    else if (milliseconds < 0.0) {
        message = formatDelta(milliseconds) + ' behind UTC';
    }
    else {
        message = ' even with UTC';
    }
    element = document.getElementById('localoffset');
    element.innerText = message;
}

function startTime() {
    var today=Date.now();
    today += OFFSET;
    today = new Date(today);
    document.getElementById('localtime').innerHTML = formatDate(today);
    var t = setTimeout(function(){startTime()},500);
}

getLocation(displayOffset);
<commit_msg>Use absolute value when creating pretty time display to avoid 23:59:59 or similar showing for negative offsets<commit_after>OFFSET = 0;

function getLocation(callback) {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(callback);
    } else {
        callback(false);
    }
}

function calculateOffset(position) {
    var fraction = position.coords.longitude / 180.0;
    // milliseconds * seconds * minutes * hours
    var multiplicand = 1000 * 60 * 60 * 12;
    var milliseconds = fraction * multiplicand;
    return milliseconds;
}

function pad(n) {
    return (n < 10) ? ("0" + n) : n;
}

function formatDate(date) {
    return pad(date.getUTCHours()) + ':' + pad(date.getUTCMinutes()) + ':' + pad(date.getUTCSeconds());
}

function formatDelta(ms) {
    var date = new Date(Math.abs(ms));
    return formatDate(date);
}

function displayOffset(position) {
    var milliseconds = calculateOffset(position);
    OFFSET = milliseconds;
    var message;
    if (milliseconds > 0.0) {
        message = formatDelta(milliseconds) + ' ahead of UTC';
    }
    else if (milliseconds < 0.0) {
        message = formatDelta(milliseconds) + ' behind UTC';
    }
    else {
        message = ' even with UTC';
    }
    element = document.getElementById('localoffset');
    element.innerText = message;
}

function startTime() {
    var today=Date.now();
    today += OFFSET;
    today = new Date(today);
    document.getElementById('localtime').innerHTML = formatDate(today);
    var t = setTimeout(function(){startTime()},500);
}

getLocation(displayOffset);

{'fraction_non_alphanumeric': 0.1300097751710655, 'fraction_numerical': 0.018246985988921473, 'mean_word_length': 3.311797752808989, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '597492', 'n_tokens_mistral': 968, 'n_tokens_neox': 908, 'n_words': 220}