Update to include a normalized date
This commit is contained in:
parent
021a84b957
commit
a86bc10e51
23
package-lock.json
generated
23
package-lock.json
generated
@ -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",
|
||||
|
@ -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"
|
||||
|
@ -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>
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user