Compare commits

...
This repository has been archived on 2025-03-13. You can view files and clone it, but cannot push or open issues or pull requests.

1 Commits

Author SHA1 Message Date
9e096eb4e7
Added some classes 2024-12-29 19:25:43 +01:00
6 changed files with 143 additions and 0 deletions

9
index.html Normal file
View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>System Namespace</title>
</head>
<body>
<script type="module" src="main.js"></script>
</body>
</html>

16
main.js Normal file
View File

@ -0,0 +1,16 @@
import { System } from './src/System/export.js';
const span1 = new System.TimeSpan(1, 30, 15, 500);
console.log(span1.toString());
const span2 = System.TimeSpan.fromMinutes(90);
console.log(span2.toString());
////
const span = new System.TimeSpan(1, 30, 0);
console.log(span.toString());
const sum = System.Math.add(10, 5);
console.log(sum);

9
src/System/Math.js Normal file
View File

@ -0,0 +1,9 @@
export class Math {
static add(a, b) {
return a + b;
}
static subtract(a, b) {
return a - b;
}
}

View File

@ -0,0 +1,5 @@
export class TestClass {
constructor() {
}
}

93
src/System/TimeSpan.js Normal file
View File

@ -0,0 +1,93 @@
export class TimeSpan {
constructor(hours = 0, minutes = 0, seconds = 0, milliseconds = 0) {
this.milliseconds = milliseconds + seconds * 1000 + minutes * 60000 + hours * 3600000;
}
static fromMilliseconds(milliseconds) {
return new TimeSpan(0, 0, 0, milliseconds);
}
static fromSeconds(seconds) {
return new TimeSpan(0, 0, seconds);
}
static fromMinutes(minutes) {
return new TimeSpan(0, minutes);
}
static fromHours(hours) {
return new TimeSpan(hours);
}
static fromDays(days) {
return new TimeSpan(days * 24);
}
get totalMilliseconds() {
return this.milliseconds;
}
get totalSeconds() {
return this.milliseconds / 1000;
}
get totalMinutes() {
return this.milliseconds / 60000;
}
get totalHours() {
return this.milliseconds / 3600000;
}
get totalDays() {
return this.milliseconds / 86400000;
}
get millisecondsPart() {
return this.milliseconds % 1000;
}
get secondsPart() {
return Math.floor(this.milliseconds / 1000) % 60;
}
get minutesPart() {
return Math.floor(this.milliseconds / 60000) % 60;
}
get hoursPart() {
return Math.floor(this.milliseconds / 3600000) % 24;
}
get daysPart() {
return Math.floor(this.milliseconds / 86400000);
}
get ticks() {
return this.milliseconds * 10000;
}
add(timeSpan) {
return TimeSpan.fromMilliseconds(this.milliseconds + timeSpan.totalMilliseconds);
}
subtract(timeSpan) {
return TimeSpan.fromMilliseconds(this.milliseconds - timeSpan.totalMilliseconds);
}
toString() {
const pad = (n) => n.toString().padStart(2, '0');
return `${this.daysPart > 0 ? this.daysPart + '.' : ''}${pad(this.hoursPart)}:${pad(this.minutesPart)}:${pad(this.secondsPart)}.${this.millisecondsPart}`;
}
}
/*
const span1 = new TimeSpan(1, 30, 15, 500);
console.log(span1.toString());
const span2 = TimeSpan.fromMinutes(90);
console.log(span2.toString());
const sum = span1.add(span2);
console.log(sum.toString());
*/

11
src/System/export.js Normal file
View File

@ -0,0 +1,11 @@
import { TimeSpan } from './TimeSpan.js';
import { Math } from './Math.js';
import { TestClass } from './TestNamespace/TestClass.js';
export const System = {
TimeSpan,
Math,
TestNamespace: {
TestClass
}
};