Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeZoneDB API #447

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions New_APIs/TimeZoneDB API/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# TimeZoneDB API Demo

This is a simple web application that interacts with the TimeZoneDB API to provide time zone information and conversion features. The application allows users to:

1. **Get the current time zone** for a specific location.
2. **Convert time** between two different time zones.

## Features

- **Location-based Time Zone Retrieval**: Enter a location to retrieve the current time zone information.
- **Time Zone Conversion**: Convert time from one time zone to another.

## Technologies Used

- **HTML/CSS/JavaScript**: The frontend is built using standard web technologies.
- **Node.js & Express**: A simple Node.js server is used to serve the static files.
- **TimeZoneDB API**: The backend service that provides time zone data.

## Installation

### Prerequisites

- **Node.js** (v12+ recommended)
- **npm** (Node Package Manager)

### Steps

1. **Clone the Repository**:

```
git clone https://github.com/your-username/timezonedb-api-demo.git
cd timezonedb-api-demo
```

2. **Install Dependecies**
```
npm install
```

## Contributor
### Sree Vidya
31 changes: 31 additions & 0 deletions New_APIs/TimeZoneDB API/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>TimeZoneDB API Demo</title>
</head>
<body>
<header>
<h1>TimeZoneDB API</h1>
</header>
<main>
<div class="content-section">
<h2>Get Current Time Zone</h2>
<input type="text" id="locationInput" placeholder="Enter Location (e.g., London)">
<button id="getTimeZoneButton">Get Time Zone</button>
<h2>Convert Time Zone</h2>
<input type="text" id="fromTimeZone" placeholder="From Time Zone (e.g., UTC)">
<input type="text" id="toTimeZone" placeholder="To Time Zone (e.g., PST)">
<input type="text" id="timeToConvert" placeholder="Time to Convert (e.g., 2024-08-09 15:00)">
<button id="convertTimeButton">Convert Time</button>
</div>
<div class="result-section">
<h2>Results</h2>
<pre id="results"></pre>
</div>
</main>
<script src="index.js"></script>
</body>
</html>
47 changes: 47 additions & 0 deletions New_APIs/TimeZoneDB API/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
document.getElementById('getTimeZoneButton').addEventListener('click', getTimeZone);
document.getElementById('convertTimeButton').addEventListener('click', convertTime);

const apiKey = 'YOUR_API_KEY'; // Replace with your TimeZoneDB API key
const apiUrl = 'http://api.timezonedb.com/v2.1/';

async function getTimeZone() {
const location = document.getElementById('locationInput').value;
if (!location) {
alert('Please enter a location.');
return;
}

try {
const response = await fetch(`${apiUrl}get-time-zone?key=${apiKey}&format=json&by=zone&zone=${location}`);
const data = await response.json();
displayResults(data);
} catch (error) {
console.error('Error:', error);
alert('Failed to fetch time zone data.');
}
}

async function convertTime() {
const fromTimeZone = document.getElementById('fromTimeZone').value;
const toTimeZone = document.getElementById('toTimeZone').value;
const timeToConvert = document.getElementById('timeToConvert').value;

if (!fromTimeZone || !toTimeZone || !timeToConvert) {
alert('Please fill in all fields.');
return;
}

try {
const response = await fetch(`${apiUrl}convert-time-zone?key=${apiKey}&format=json&from=${fromTimeZone}&to=${toTimeZone}&time=${timeToConvert}`);
const data = await response.json();
displayResults(data);
} catch (error) {
console.error('Error:', error);
alert('Failed to convert time.');
}
}

function displayResults(data) {
const results = document.getElementById('results');
results.textContent = JSON.stringify(data, null, 2);
}
26 changes: 26 additions & 0 deletions New_APIs/TimeZoneDB API/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions New_APIs/TimeZoneDB API/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "timezonedb-api-demo",
"version": "1.0.0",
"description": "A simple app to demonstrate the TimeZoneDB API",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"author": "Your Name",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"timezonedb-api-demo": "file:"
}
}
8 changes: 8 additions & 0 deletions New_APIs/TimeZoneDB API/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const express = require('express');
const app = express();

app.use(express.static('public'));

app.listen(3000, () => {
console.log('Server is running on port 3000');
});
71 changes: 71 additions & 0 deletions New_APIs/TimeZoneDB API/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #be1d9b, #ff5e62);
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
}

header {
text-align: center;
margin-bottom: 20px;
}

header h1 {
font-size: 3em;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

main {
width: 90%;
max-width: 600px;
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
padding: 20px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.content-section,
.result-section {
margin-bottom: 20px;
text-align: center;
}

input[type="text"] {
display: block;
margin: 10px auto;
font-size: 1em;
border: none;
border-radius: 5px;
outline: none;
padding: 10px;
width: 80%;
max-width: 400px;
}

button {
padding: 10px 20px;
font-size: 1em;
background-color: #444;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}

button:hover {
background-color: #666;
}

pre#results {
text-align: left;
background: rgba(0, 0, 0, 0.5);
padding: 10px;
border-radius: 5px;
color: #fff;
}
Loading