npm.io
1.3.1 • Published 6 years ago

@vybornyj/input-to-utc

Licence
MIT
Version
1.3.1
Deps
1
Size
14 kB
Vulns
0
Weekly
0

publish npm version npm minified size license type coverage eslint prettier

I recommend using module on the server side to keep API keys private.

Required API Keys

Google Cloud (for Place Autocomplete API and Maps Geocode API)

https://cloud.google.com

Get $200 in free usage for Maps, Routes, and Places every month

TimeZoneDB (for Get Time Zone API)

https://timezonedb.com/api

TimeZoneDB API is free for personal and non-commercial usage. There are no limits on how many queries you can make, but there is a rate limit where you can only send request to the server once per second. Additional queries will get blocked.

Install

npm i @vybornyj/input-to-utc

or

yarn add @vybornyj/input-to-utc

Usage

Step 1: Autocomplete City and Get cityId

import { autocompleteCity } from '@vybornyj/input-to-utc'

const GOOGLE_API_KEY = '000000000000000000000000000000000000000'
const city = 'Lond'

const cities: {city: string, cityId: string}[] = await autocompleteCity(GOOGLE_API_KEY, city)

Step 2: Get dateUTC by input date-time and cityId

import { calcDateUtc } from '@vybornyj/input-to-utc'

const GOOGLE_API_KEY = '000000000000000000000000000000000000000'
const TIMEZONEDB_API_KEY = '000000000000'
const cityId = cities[0].cityId
const year = '2027'
const month = '12'
const day = '31'
const hours = '23'
const minutes = '59'

const dateUTC: Date | null = await calcDateUtc(GOOGLE_API_KEY, TIMEZONEDB_API_KEY, cityId, { year, month, day, hours, minutes })