Update to include a normalized date

This commit is contained in:
William Moore 2024-05-14 13:12:47 -05:00
parent 021a84b957
commit a86bc10e51
4 changed files with 14 additions and 25 deletions

23
package-lock.json generated
View File

@ -1,16 +1,14 @@
{
"name": "lavender",
"name": "timepiece",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "lavender",
"name": "timepiece",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"date-fns": "^3.0.0",
"date-fns-tz": "^3.1.3",
"dotenv": "^16.1.4",
"lit": "^2.7.5",
"typescript": "^5.1.3"
@ -1797,23 +1795,6 @@
"type": "^1.0.1"
}
},
"node_modules/date-fns": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-3.6.0.tgz",
"integrity": "sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/kossnocorp"
}
},
"node_modules/date-fns-tz": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/date-fns-tz/-/date-fns-tz-3.1.3.tgz",
"integrity": "sha512-ZfbMu+nbzW0mEzC8VZrLiSWvUIaI3aRHeq33mTe7Y38UctKukgqPR4nTDwcwS4d64Gf8GghnVsroBuMY3eiTeA==",
"peerDependencies": {
"date-fns": "^3.0.0"
}
},
"node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",

View File

@ -13,8 +13,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"date-fns": "^3.0.0",
"date-fns-tz": "^3.1.3",
"dotenv": "^16.1.4",
"lit": "^2.7.5",
"typescript": "^5.1.3"

View File

@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<!DOCTYPE html>
<html>
<head>

View File

@ -15,9 +15,9 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { LitElement, css, html } from 'lit';
import { customElement } from 'lit/decorators.js';
import { format } from 'date-fns-tz';
@customElement('wmoore-timepiece')
export class Timepiece extends LitElement {
@ -28,6 +28,15 @@ export class Timepiece extends LitElement {
this.reloadTime();
}
dayOfTheYear(date: Date) {
return Math.floor((date.getTime() - (new Date(date.getFullYear(), 0, 0)).getTime()) / 86400000);
}
totalDaysInTheYear(date: Date) {
const maxDate = (new Date(date.getFullYear(), 11, 30)).getTime();
const minDate = (new Date(date.getFullYear(), 0, 0)).getTime();
return Math.floor((maxDate - minDate) / 86400000);
}
async reloadTime() {
const date = new Date();
@ -39,7 +48,7 @@ export class Timepiece extends LitElement {
beats = Math.round(beats * 100) / 100;
this.setData(`${format(date, 'yyyy-MM-dd', {timeZone: 'UTC'})}@${beats.toFixed(2)}`);
this.setData(`${date.getFullYear()}.${((this.dayOfTheYear(date)/this.totalDaysInTheYear(date))*100).toFixed(0)}@${beats.toFixed(2)}`);
setTimeout(() => this.reloadTime(), 100);
}