-
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.
Add swatch time, imood, no antialiasing
- Loading branch information
Showing
4 changed files
with
47 additions
and
3 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
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
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 @@ | ||
// Returns the current Swatch beat | ||
function GetSwatchTime(showDecimals = true) { | ||
// get date in UTC/GMT | ||
var date = new Date(); | ||
var hours = date.getUTCHours(); | ||
var minutes = date.getUTCMinutes(); | ||
var seconds = date.getUTCSeconds(); | ||
var milliseconds = date.getUTCMilliseconds(); | ||
// add hour to get time in Switzerland | ||
hours = hours == 23 ? 0 : hours + 1; | ||
// time in seconds | ||
var timeInMilliseconds = ((hours * 60 + minutes) * 60 + seconds) * 1000 + milliseconds; | ||
// there are 86.4 seconds in a beat | ||
var millisecondsInABeat = 86400; | ||
// calculate beats to two decimal places | ||
if (showDecimals) { | ||
return Math.abs(timeInMilliseconds / millisecondsInABeat).toFixed(2); | ||
} else { | ||
return Math.floor(Math.abs(timeInMilliseconds / millisecondsInABeat)); | ||
} | ||
} |
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