mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Merge branch 'feat/timezone-converter' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # pnpm-lock.yaml # src/tools/index.ts
This commit is contained in:
commit
dc273dd02e
6 files changed
+167
-3
No files matched your search
@@ -106,6 +106,7 @@
|
||||
"countries-db": "^1.2.0",
|
||||
"composerize": "^1.6.12",
|
||||
"countries-and-timezones": "^3.7.2",
|
||||
"countries-and-timezones": "^3.6.0",
|
||||
"country-code-lookup": "^0.1.0",
|
||||
"crc": "^4.3.2",
|
||||
"cron-validator": "^1.3.1",
|
||||
@@ -135,6 +136,7 @@
|
||||
"fuse.js": "^6.6.2",
|
||||
"hash-wasm": "^4.11.0",
|
||||
"generate-schema": "^2.6.0",
|
||||
"get-timezone-offset": "^1.0.5",
|
||||
"highlight.js": "^11.7.0",
|
||||
"iarna-toml-esm": "^3.0.5",
|
||||
"ibantools": "^4.3.3",
|
||||
|
||||
Generated
+10
-3
@@ -177,7 +177,7 @@ dependencies:
|
||||
specifier: ^0.6.2
|
||||
version: 0.6.2
|
||||
countries-and-timezones:
|
||||
specifier: ^3.7.2
|
||||
specifier: ^3.6.0
|
||||
version: 3.7.2
|
||||
countries-db:
|
||||
specifier: ^1.2.0
|
||||
@@ -263,6 +263,9 @@ dependencies:
|
||||
generate-schema:
|
||||
specifier: ^2.6.0
|
||||
version: 2.6.0
|
||||
get-timezone-offset:
|
||||
specifier: ^1.0.5
|
||||
version: 1.0.5
|
||||
hash-wasm:
|
||||
specifier: ^4.11.0
|
||||
version: 4.11.0
|
||||
@@ -6296,7 +6299,7 @@ packages:
|
||||
/@vueuse/shared@10.0.0(vue@3.3.4):
|
||||
resolution: {integrity: sha512-Zh3LgJqvUBWVY3SiMvXanTcfAneGbt63QPczBRDNgQ6jd/ehodO9a1lCFzaA6SWJJoI+ugVTjHFYJdoR656DVQ==}
|
||||
dependencies:
|
||||
vue-demi: 0.14.10(vue@3.3.4)
|
||||
vue-demi: 0.14.5(vue@3.3.4)
|
||||
transitivePeerDependencies:
|
||||
- '@vue/composition-api'
|
||||
- vue
|
||||
@@ -9235,6 +9238,11 @@ packages:
|
||||
get-intrinsic: 1.2.2
|
||||
dev: true
|
||||
|
||||
/get-timezone-offset@1.0.5:
|
||||
resolution: {integrity: sha512-+B+/vEJ9qJgZheDVNmuY+4il8sJhTFXRvSiiqyRfwiCEhTaZqn/yCoNToDzQL+Mv9DLKlyO1bSIP5nUCJQN9Aw==}
|
||||
engines: {node: '>=4.0.0'}
|
||||
dev: false
|
||||
|
||||
/get-tsconfig@4.7.2:
|
||||
resolution: {integrity: sha512-wuMsz4leaj5hbGgg4IvDU0bqJagpftG5l5cXIAvo8uZrqn0NJqwtfupTN00VnkQJPcIRrxYrm1Ue24btpCha2A==}
|
||||
dependencies:
|
||||
@@ -15526,7 +15534,6 @@ packages:
|
||||
|
||||
/yamljs@0.3.0:
|
||||
resolution: {integrity: sha512-C/FsVVhht4iPQYXOInoxUM/1ELSf9EsgKH34FofQOp6hwCPrW4vG4w5++TED3xRUo8gD7l0P1J1dLlDYzODsTQ==}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
argparse: 1.0.10
|
||||
glob: 7.2.3
|
||||
|
||||
@@ -79,6 +79,7 @@ import { tool as imageToCss } from './image-to-css';
|
||||
import { tool as jsonToGo } from './json-to-go';
|
||||
import { tool as jsonToSchema } from './json-to-schema';
|
||||
import { tool as qrCodeDecoder } from './qr-code-decoder';
|
||||
import { tool as timezoneConverter } from './timezone-converter';
|
||||
import { tool as markdownToHtml } from './markdown-to-html';
|
||||
import { tool as nginxFormatter } from './nginx-formatter';
|
||||
import { tool as potrace } from './potrace';
|
||||
@@ -211,6 +212,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
name: 'Converter',
|
||||
components: [
|
||||
dateTimeConverter,
|
||||
timezoneConverter,
|
||||
baseConverter,
|
||||
romanNumeralConverter,
|
||||
base64StringConverter,
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
declare module "get-timezone-offset" {
|
||||
export default function(timeZoneName: string, date: Date);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { CalendarTime } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Timezone Converter',
|
||||
path: '/timezone-converter',
|
||||
description: 'Convert Date-Time from a timezone to others and get timezone vs countries infos',
|
||||
keywords: ['timezone', 'tz', 'date', 'time', 'country', 'converter'],
|
||||
component: () => import('./timezone-converter.vue'),
|
||||
icon: CalendarTime,
|
||||
createdAt: new Date('2024-08-15'),
|
||||
});
|
||||
@@ -0,0 +1,138 @@
|
||||
<script setup lang="ts">
|
||||
import ctz from 'countries-and-timezones';
|
||||
import getTimezoneOffset from 'get-timezone-offset';
|
||||
|
||||
const browserTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
const allTimezones = Object.values(ctz.getAllTimezones()).map(tz => ({
|
||||
value: tz.name,
|
||||
label: `${tz.name === browserTimezone ? 'Browser TZ - ' : ''}${tz.name} (${tz.utcOffset === tz.dstOffset ? tz.utcOffsetStr : `${tz.utcOffsetStr}/${tz.dstOffsetStr}`})`,
|
||||
}));
|
||||
|
||||
function convertMinsToHrsMins(minutes: number) {
|
||||
const h = String(Math.floor(minutes / 60)).padStart(2, '0');
|
||||
const m = String(minutes % 60).padStart(2, '0');
|
||||
return `${h}:${m}`;
|
||||
}
|
||||
|
||||
const otherTimezones = useStorage<{ name: string }[]>('timezone-conv:zones', [{ name: 'Etc/GMT' }]);
|
||||
const currentTimezone = useStorage<string>('timezone-conv:current', browserTimezone);
|
||||
const use24HourTimeFormat = useStorage<boolean>('timezone-conv:24h', true);
|
||||
const format = computed(() => use24HourTimeFormat.value ? 'yyyy-MM-dd HH:mm:ss' : 'yyyy-MM-dd hh:mm:ss a');
|
||||
const timePickerProps = computed(() => use24HourTimeFormat.value ? ({ use12Hours: false }) : ({ use12Hours: true }));
|
||||
|
||||
const now = Date.now();
|
||||
const currentDatetimeRange = ref<[number, number]>([now, now]);
|
||||
const currentTimezoneOffset = computed(() => {
|
||||
return convertMinsToHrsMins(-getTimezoneOffset(currentTimezone.value, new Date(currentDatetimeRange.value[0])));
|
||||
});
|
||||
function convertToTimezone(tz: string, timestamp: number) {
|
||||
return new Date(
|
||||
timestamp
|
||||
+ getTimezoneOffset(currentTimezone.value, new Date()) * 60 * 1000
|
||||
- getTimezoneOffset(browserTimezone, new Date()) * 60 * 1000,
|
||||
).toLocaleString(undefined,
|
||||
{ timeZone: tz, timeZoneName: undefined, hour12: !use24HourTimeFormat.value });
|
||||
}
|
||||
|
||||
const tzToCountriesInput = ref(browserTimezone);
|
||||
const tzToCountriesOutput = computed(() => ctz.getCountriesForTimezone(tzToCountriesInput.value));
|
||||
|
||||
const allCountries = Object.values(ctz.getAllCountries()).map(c => ({
|
||||
value: c.id,
|
||||
label: `${c.name} (${c.id})`,
|
||||
}));
|
||||
const countryToTimezonesInput = ref('FR');
|
||||
const countryToTimezonesOutput = computed(() => ctz.getTimezonesForCountry(countryToTimezonesInput.value));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card title="Timezones Date-Time Converter" mb-2>
|
||||
<c-select
|
||||
v-model:value="currentTimezone"
|
||||
label="Timezone"
|
||||
label-position="left"
|
||||
searchable
|
||||
:options="allTimezones"
|
||||
mb-2
|
||||
/>
|
||||
<n-date-picker
|
||||
:key="format"
|
||||
v-model:value="currentDatetimeRange"
|
||||
type="datetimerange"
|
||||
:format="format"
|
||||
:time-picker-props="timePickerProps"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<n-space justify="space-evenly">
|
||||
<n-form-item label="Current Timezone Offset:" label-placement="left">
|
||||
<n-input :value="currentTimezoneOffset" readonly style="width:5em" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Use 24 hour time format" label-placement="left">
|
||||
<n-switch v-model:value="use24HourTimeFormat" />
|
||||
</n-form-item>
|
||||
</n-space>
|
||||
|
||||
<c-card title="Date-Time in other timezones">
|
||||
<n-dynamic-input
|
||||
v-model:value="otherTimezones"
|
||||
show-sort-button
|
||||
:on-create="() => ({ name: browserTimezone })"
|
||||
>
|
||||
<template #default="{ value }">
|
||||
<div flex flex-wrap items-center gap-1>
|
||||
<n-select
|
||||
v-model:value="value.name"
|
||||
filterable
|
||||
placeholder="Please select a timezone"
|
||||
:options="allTimezones"
|
||||
w-full
|
||||
/>
|
||||
<div w-full flex items-baseline gap-1>
|
||||
<n-input style="min-width: 49%" readonly :value="convertToTimezone(value.name, currentDatetimeRange[0])" />
|
||||
<n-input style="min-width: 49%" readonly :value="convertToTimezone(value.name, currentDatetimeRange[1])" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</n-dynamic-input>
|
||||
</c-card>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Country to Timezones" mb-2>
|
||||
<c-select
|
||||
v-model:value="countryToTimezonesInput"
|
||||
label="Country"
|
||||
label-position="left"
|
||||
searchable
|
||||
:options="allCountries"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<ul>
|
||||
<li v-for="(tz, ix) in countryToTimezonesOutput" :key="ix">
|
||||
{{ tz.name }} ({{ tz.countries.join(', ') }}): UTC= {{ tz.utcOffsetStr }}, DST= {{ tz.dstOffsetStr }}
|
||||
</li>
|
||||
</ul>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Timezones to Countries" mb-2>
|
||||
<c-select
|
||||
v-model:value="tzToCountriesInput"
|
||||
label="Timezone"
|
||||
label-position="left"
|
||||
searchable
|
||||
:options="allTimezones"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<ul>
|
||||
<li v-for="(country, ix) in tzToCountriesOutput" :key="ix">
|
||||
{{ country.name }} ({{ country.id }}): {{ country.timezones.join(', ') }}
|
||||
</li>
|
||||
</ul>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user