Skip to content

Commit

Permalink
Use luxon to get day-of-year instead of API call
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrSaber committed Sep 8, 2024
1 parent f2d62a4 commit 2805594
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
Binary file modified bun.lockb
Binary file not shown.
32 changes: 17 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,31 @@
"format": "prettier --plugin-search-dir . --write ."
},
"devDependencies": {
"@sveltejs/kit": "^1.20.4",
"@sveltejs/kit": "^1.30.4",
"@types/bun": "^1.1.8",
"@types/lodash.memoize": "^4.1.9",
"@types/lodash.throttle": "^4.1.9",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte": "^2.30.0",
"prettier": "^2.8.0",
"@types/luxon": "^3.4.2",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-svelte": "^2.43.0",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.1",
"svelte": "^4.0.5",
"svelte": "^4.2.19",
"svelte-adapter-bun": "^0.5.2",
"svelte-check": "^3.4.3",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^4.4.2",
"vitest": "^0.34.0"
"svelte-check": "^3.8.6",
"tslib": "^2.7.0",
"typescript": "^5.5.4",
"vite": "^4.5.3",
"vitest": "^0.34.6"
},
"type": "module",
"dependencies": {
"cheerio": "^1.0.0-rc.12",
"cheerio": "^1.0.0",
"lodash.memoize": "^4.1.2",
"lodash.throttle": "^4.1.1"
"lodash.throttle": "^4.1.1",
"luxon": "^3.5.0"
}
}
2 changes: 2 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const UK_ID = 53;
export const CAMBRIDGE_ID = 20245;

export const UK_TIME_ZONE = 'Europe/London';
6 changes: 3 additions & 3 deletions src/routes/api/hijri-date/[country]/+server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { UK_ID } from '$lib/constants.js';
import { UK_ID, UK_TIME_ZONE } from '$lib/constants.js';
import { getCacheStore } from '$lib/server';
import type { HijriDate, HijriDateAnchor } from '$lib/types/api.js';
import { json } from '@sveltejs/kit';
import * as cheerio from 'cheerio';
import { DateTime } from 'luxon';

export async function GET({ params }) {
const country = params.country.toLowerCase();
Expand All @@ -12,8 +13,7 @@ export async function GET({ params }) {
}

try {
const ukDate = await fetch('https://worldtimeapi.org/api/timezone/Europe/London').then((d) => d.json());
const dayOfYear = ukDate.day_of_year as number;
const dayOfYear = DateTime.now().setZone(UK_TIME_ZONE).ordinal;

const cacheStore = await getCacheStore();
const cacheKey = `api::hijri-date::${country}`;
Expand Down
12 changes: 11 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
# bun ./bun.lockb --hash: 4707F77E13EC78AF-65d179dfc434e78b-2F3BB03CE2AC5E39-dd5f65310c740cff
# bun ./bun.lockb --hash: CA400170BB5B95E8-9cfacbd28eddefc0-12748497665CA93C-3ce579ef8e176d65


"@aashutoshrathi/word-wrap@^1.2.3":
Expand Down Expand Up @@ -623,6 +623,11 @@
dependencies:
"@types/lodash" "*"

"@types/luxon@^3.4.2":
version "3.4.2"
resolved "https://registry.npmjs.org/@types/luxon/-/luxon-3.4.2.tgz"
integrity sha512-TifLZlFudklWlMBfhubvgqTXRzLDI5pCbGa4P8a3wPyUQSW+1xQ5eDsreP9DWHX3tjq1ke96uYG/nwundroWcA==

"@types/node@>= 14":
version "20.6.4"
resolved "https://registry.npmjs.org/@types/node/-/node-20.6.4.tgz"
Expand Down Expand Up @@ -1808,6 +1813,11 @@ loupe@^2.3.6:
dependencies:
get-func-name "^2.0.1"

luxon@^3.5.0:
version "3.5.0"
resolved "https://registry.npmjs.org/luxon/-/luxon-3.5.0.tgz"
integrity sha512-rh+Zjr6DNfUYR3bPwJEnuwDdqMbxZW7LOQfUN4B54+Cl+0o5zaU9RJ6bcidfDtC1cWCZXQ+nvX8bf6bAji37QQ==

magic-string@^0.30.0, magic-string@^0.30.3:
version "0.30.3"
resolved "https://registry.npmjs.org/magic-string/-/magic-string-0.30.3.tgz"
Expand Down

0 comments on commit 2805594

Please sign in to comment.