PageSourceSearch

https://timetravel.on.websim.com/calculator-utils.js

js timetravel.on.websim.com collected 2026-10-03 05:06:19 UTC 2,557 bytes, 58 lines download raw bytes

1// New file: calculator-utils.js
2// Contains utility functions for calculator.js to keep the main file concise
3
4// Import necessary constants
5import {
6    baseLightSpeedKmh,
7    kmToMiles,
8    movementSpeedsKmh
9} from './speeds.js';
10
11// Function to calculate the combined speed based on selected checkboxes and unit
12function calculateCombinedSpeed(currentUnit, movementCheckboxes) {
13    // Start at zero and only add the speed of light when its checkbox is selected
14    let speedInKmh = 0;
15    console.log(`Starting combined speed (base 0): ${speedInKmh.toLocaleString()} km/h`);
16
17    // Convert NodeList to array for easier iteration
18    const checkboxesArray = Array.from(movementCheckboxes);
19
20    checkboxesArray.forEach(checkbox => {
21        if (!checkbox.checked) return;
22
23        if (checkbox.value === 'speedOfLightBase') {
24            // Add the light speed only if selected
25            speedInKmh += baseLightSpeedKmh;
26            console.log(`Adding Speed of Light: ${baseLightSpeedKmh.toLocaleString()} km/h. New total (km/h): ${speedInKmh.toLocaleString()}`);
27        } else if (movementSpeedsKmh[checkbox.value]) {
28            const speedToAdd = movementSpeedsKmh[checkbox.value];
29            speedInKmh += speedToAdd;
30            console.log(`Adding ${checkbox.value}: ${speedToAdd.toLocaleString()} km/h. New total (km/h): ${speedInKmh.toLocaleString()}`);
31        } else {
32            console.warn(`Checkbox value "${checkbox.value}" is checked but not found in movementSpeedsKmh.`);
33        }
34    });
35
36    console.log(`Final speed in km/h: ${speedInKmh.toLocaleString()}`);
37    let currentSpeed = (currentUnit === 'mph') ? speedInKmh * kmToMiles : speedInKmh;
38    const displayUnit = currentUnit === 'mph' ? 'mph' : 'km/h';
39    console.log(`Final speed in ${displayUnit}: ${currentSpeed.toLocaleString()}`);
40    return currentSpeed;
41}
42
43// removed updateDisplay() - Logic moved to calculator-ui.js
44// removed updateDistance() - Logic consolidated in calculator.js controller
45
46// Function to get local date and time in the format for input fields
47function getLocalDateTime() {
48    const now = new Date();
49    const timezoneOffset = now.getTimezoneOffset() * 60000;
50    // Get ISO string with milliseconds
51    const localISOTime = new Date(now.getTime() - timezoneOffset).toISOString();
52    const localDate = localISOTime.slice(0, 10);
53    // Extract HH:mm:ss.sss (12 chars long starting at index 11)
54    const localTime = localISOTime.slice(11, 23);
55    return { localDate, localTime };
56}
57
58export { calculateCombinedSpeed, getLocalDateTime };

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.