-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f693538
Showing
6 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Max Rugen | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Industrial Hours Calculator | ||
|
||
This simple web-based Industrial Hours Calculator allows you to convert time durations between different formats – hours and minutes. You can use it to calculate industrial hours for a given time input in either "hh:mm" or minutes format. | ||
|
||
## Usage | ||
|
||
1. Open Industrial Hours Calculator at [maxrugen.github.io/industrial-hours](https://maxrugen.github.io/industrial-hours) or by running the HTML file locally. | ||
2. Enter the duration in the input field. | ||
3. Click the "Calculate" button to convert the input into industrial hours. | ||
|
||
## Format | ||
|
||
- You can input time in either "hh:mm" format or as minutes. | ||
- Examples: | ||
- Entering "1:30" or "90" will result in 1.5 industrial hours. | ||
|
||
## License | ||
|
||
This Industrial Hours Calculator is licensed under the [MIT License](LICENSE). Feel free to use, modify, and distribute the code. | ||
|
||
## How to Contribute | ||
|
||
If you find any issues or have suggestions for improvement, feel free to [open an issue](https://github.com/maxrugen/industrial-hours/issues) or create a pull request. We welcome contributions! | ||
|
||
## Disclaimer | ||
|
||
This Industrial Hours Calculator is a basic tool and should be used with caution. The author is not responsible for any inaccuracies or problems that may arise from its use. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Industrial Hours Calculator</title> | ||
<link rel="stylesheet" type="text/css" href="style.css"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
</head> | ||
<body> | ||
<div id="converter"> | ||
<h2>Industrial Hours Calculator</h2> | ||
<label for="timeInput">Enter duration (hh:mm or minutes):</label> | ||
<br><br><input type="text" id="timeInput" placeholder="e.g. 1:30 or 90"> | ||
<button onclick="convertTime()">Calculate</button> | ||
<p id="result"></p> | ||
<p id="error"></p> | ||
</div> | ||
<script defer src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Function to read time input from the DOM | ||
function readTimeInput() { | ||
return document.getElementById("timeInput").value; | ||
} | ||
// Function to display an error message on the DOM | ||
function displayError(message, resultElement, errorElement) { | ||
errorElement.textContent = message; | ||
resultElement.textContent = ""; // Clear any previous result | ||
resultElement.classList.remove("success"); // Remove success styling | ||
errorElement.classList.add("error"); // Apply error styling | ||
} | ||
// Function to display the result on the DOM | ||
function displayResult(result, resultElement, errorElement) { | ||
resultElement.textContent = result; | ||
errorElement.textContent = ""; // Clear any previous error | ||
errorElement.classList.remove("error"); // Remove error styling | ||
resultElement.classList.add("success"); // Apply success styling | ||
} | ||
// Function to calculate industrial hours from hours and minutes | ||
function calculateIndustrialHours(hours, minutes) { | ||
return hours + minutes / 60; | ||
} | ||
// Function to format a number to two decimal places | ||
function formatToTwoDecimalPlaces(number) { | ||
return number.toFixed(2); | ||
} | ||
// Function to validate input values | ||
function validateInput(hours, minutes) { | ||
return !isNaN(hours) && !isNaN(minutes) && hours >= 0 && hours <= 23 && minutes >= 0 && minutes <= 59; | ||
} | ||
// Main conversion function | ||
function convertTime() { | ||
const timeInput = readTimeInput(); | ||
const resultElement = document.getElementById("result"); | ||
const errorElement = document.getElementById("error"); | ||
if (timeInput.trim() === "") { | ||
displayError("Please enter a duration in the format hh:mm or in minutes.", resultElement, errorElement); | ||
} else { | ||
errorElement.textContent = ""; | ||
if (timeInput.includes(":")) { | ||
const [hours, minutes] = timeInput.split(":").map(part => parseInt(part)); | ||
if (validateInput(hours, minutes)) { | ||
const decimalHours = calculateIndustrialHours(hours, minutes); | ||
displayResult(`Industrial Hours: ${formatToTwoDecimalPlaces(decimalHours)} hours`, resultElement, errorElement); | ||
} else { | ||
displayError("Invalid entry. Hours must be between 0 and 23, and minutes must be between 0 and 59.", resultElement, errorElement); | ||
} | ||
} else { | ||
const minutes = parseInt(timeInput); | ||
if (!isNaN(minutes) && minutes >= 0) { | ||
const decimalHours = calculateIndustrialHours(0, minutes); | ||
displayResult(`Industrial Hours: ${formatToTwoDecimalPlaces(decimalHours)} hours`, resultElement, errorElement); | ||
} else { | ||
displayError("Invalid entry. Please enter a valid duration in the format hh:mm or in minutes.", resultElement, errorElement); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* CSS for body */ | ||
body { | ||
font-family: "Lab Grotesque", sans-serif; | ||
text-align: center; | ||
} | ||
/* CSS for error state */ | ||
.error { | ||
color: red; | ||
} | ||
/* CSS for success state */ | ||
.success { | ||
color: green; | ||
} | ||
/* CSS for converter */ | ||
#converter { | ||
max-width: 400px; | ||
margin: 0 auto; | ||
padding: 20px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
} |