{"id":26432667,"url":"https://github.com/wiz-develop/server-clock","last_synced_at":"2025-03-18T06:19:33.215Z","repository":{"id":282189725,"uuid":"947762052","full_name":"wiz-develop/server-clock","owner":"wiz-develop","description":"⌚ Server-synchronized clock implementation for browsers with WebWorker support","archived":false,"fork":false,"pushed_at":"2025-03-13T08:04:53.000Z","size":10275,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-13T09:20:18.728Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wiz-develop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-13T07:58:13.000Z","updated_at":"2025-03-13T08:34:01.000Z","dependencies_parsed_at":"2025-03-13T09:20:41.251Z","dependency_job_id":null,"html_url":"https://github.com/wiz-develop/server-clock","commit_stats":null,"previous_names":["wiz-develop/server-clock"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiz-develop%2Fserver-clock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiz-develop%2Fserver-clock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiz-develop%2Fserver-clock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiz-develop%2Fserver-clock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wiz-develop","download_url":"https://codeload.github.com/wiz-develop/server-clock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244166683,"owners_count":20409180,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-18T06:19:32.705Z","updated_at":"2025-03-18T06:19:33.204Z","avatar_url":"https://github.com/wiz-develop.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @wiz-develop/server-clock\n\nサーバー時間同期型の高精度な時計ライブラリです。ブラウザで動作し、指定されたサーバーと時刻を同期して正確な時間を提供します。\n\n## 特徴\n\n- サーバー時間との精密な同期\n- WebWorkerによるパフォーマンス最適化（自動フォールバック機能付き）\n- TypeScript完全対応\n- UMD/ESM形式で多様な環境に対応\n- JST/UTC/ローカル時間の取得\n- レガシー環境（WordPress/jQuery）でも使用可能\n\n## インストール\n\nnpm:\n\n```bash\nnpm install @wiz-develop/server-clock\n```\n\nyarn:\n\n```bash\nyarn add @wiz-develop/server-clock\n```\n\npnpm:\n\n```bash\npnpm add @wiz-develop/server-clock\n```\n\n## 使用方法\n\n### モジュールとして使用する場合\n\n```javascript\nimport { ServerClock } from '@wiz-develop/server-clock';\n\n// 時計を初期化\nconst clock = new ServerClock({\n  serverUrls: ['https://example.com/time-api'], // 時刻配信サーバーのURLリスト\n  fetchInterval: 180000, // サーバー時間取得間隔(ms)\n});\n\n// 時計を開始\nclock.start();\n\n// 時計のTickイベントを監視\nclock.onTick((clockData) =\u003e {\n  console.log('UTC時間:', clockData.UTC_STR);\n  console.log('JST時間:', clockData.JST_STR);\n  console.log('ローカル時間:', clockData.LOC_STR);\n  console.log('サーバーとのオフセット:', clockData.offset, '秒');\n  console.log('同期ステータス:', clockData.status);\n});\n\n// 時計を停止 (必要な場合)\n// clock.stop();\n```\n\n### レガシー環境（scriptタグ）での使用方法\n\n```html\n\u003c!-- ライブラリを読み込み - CDNもしくはローカルファイルから --\u003e\n\u003cscript src=\"https://unpkg.com/@wiz-develop/server-clock@1.0.x/dist/bundle.min.js\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  // グローバル変数として利用可能\n  const clock = new WizDevelopServerClock.ServerClock({\n    serverUrls: ['https://example.com/time-api'], // 時刻配信サーバーのURLリスト\n    fetchInterval: 180000, // サーバー時間取得間隔(ms)\n  });\n\n  clock.start();\n\n  clock.onTick(function (clockData) {\n    document.getElementById('server-time').textContent = clockData.JST_STR;\n  });\n\u003c/script\u003e\n```\n\n### jQuery環境での使用例\n\n```html\n\u003cscript src=\"https://code.jquery.com/jquery-3.6.0.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://unpkg.com/@wiz-develop/server-clock@1.0.x/dist/bundle.min.js\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  $(function () {\n    const clock = new WizDevelopServerClock.ServerClock({\n      serverUrls: ['https://example.com/time-api'], // 時刻配信サーバーのURLリスト\n      fetchInterval: 180000, // サーバー時間取得間隔(ms)\n    });\n\n    clock.start();\n\n    clock.onTick(function (clockData) {\n      $('#server-time').text(clockData.JST_STR);\n    });\n  });\n\u003c/script\u003e\n```\n\n## 時刻配信サーバーの実装例\n\nこのライブラリは以下のようなレスポンスを返すサーバーと連携します：\n\n```json\n{\n  \"requestReceivedAt\": 1647012345678,\n  \"responseSentAt\": 1647012345679\n}\n```\n\n- `requestReceivedAt`: サーバーがリクエストを受信した時刻（ミリ秒）\n- `responseSentAt`: サーバーがレスポンスを送信した時刻（ミリ秒）\n\nNode.jsサーバーの実装例：\n\n```javascript\nconst express = require('express');\nconst app = express();\n\napp.get('/time', (req, res) =\u003e {\n  const requestReceivedAt = Date.now();\n\n  // 処理...\n\n  const responseSentAt = Date.now();\n  res.json({\n    requestReceivedAt,\n    responseSentAt,\n  });\n});\n\napp.listen(3000);\n```\n\n## ClockData オブジェクト\n\n`onTick` コールバックに渡される ClockData オブジェクトの構造：\n\n```typescript\ninterface ClockData {\n  status: 'pending' | 'client_only' | 'server_only' | 'accurate';\n  offset: number; // サーバーとの時間オフセット（秒）\n  LOCAL: Date; // ローカルタイムゾーンでの時刻（ブラウザのsetTimezone()を適用したDate）\n  LOCAL_STR: string; // ローカルタイムゾーンでの時刻（文字列形式）\n  JST: Date; // 日本標準時（UTC+9）の時刻\n  JST_STR: string; // 日本標準時の文字列表現\n  UTC: Date; // 協定世界時（UTC）の時刻\n  UTC_STR: string; // 協定世界時の文字列表現\n  LOC: Date; // サーバー時刻に基づく現地時刻\n  LOC_STR: string; // サーバー時刻に基づく現地時刻の文字列表現\n}\n```\n\n## ライセンス\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiz-develop%2Fserver-clock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwiz-develop%2Fserver-clock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiz-develop%2Fserver-clock/lists"}