This is a small app to convert time zones using python3 flask and vuejs. You can convert your current time to different time zone using this app. Main features of the application,
- Get the inserted time zones and display
- Display the current time and time zone name
- Display the different time zone date, time and time zone name.
If you like to add more time zones, you just need to add it to the json file which is in convert-time-zone-backend project's timezone.json file.
{
"timeZones": [
{
"id": "1",
"name": "US/Eastern"
},
{
"id": "2",
"name": "US/Central"
},
{
"id": "3",
"name": "YOUR TIME ZONE HERE"
},
]
}
Specially, there are two libraries used to develop this application.
This Python library allows cross platform timezone calculations using Python 2.4 or higher. ex :-
import pytz
.
.
.
currentDateAndTime = datetime.now(pytz.timezone(selectedTimeZoneName)) #used to get the different time zone value
This a simple promise based HTTP client for the browser and node.js. ex :-
import axios from 'axios';
.
.
axios.get(constants.url+'/api/getalltimezones')
.then(res =>{
let data = res.data;
this.isLoadedTimeZones = true;
const results = [];
for (const i in data.timeZones) {
results.push({
id: data.timeZones[i].id,
name: data.timeZones[i].name,
});
}
this.allTimeZones = results;
}).catch(error =>{
console.log(error);
});
Used python standard library module unittest to write test cases and test it. This helped to find bugs in the program. ex :-
#test the get all time zones API sends a status code 200
def test_1_get_all_timeZones_statusCode(self):
r = requests.get(ApiTest.ALL_TIMEZONE_URL)
self.assertEqual(r.status_code, 200)
Python flask app is hosted on the AWS EC2 instance. You can access the live endpoint using following url.
awsUrl = 'http://ec2-3-15-4-250.us-east-2.compute.amazonaws.com:8080';
Frontend with vuejs is in an apache server(cPanel) and assigned a domain name to it.
You can access the live timezoneconverter app using this url : http://timezoneconverter.cf/ (I disconnected the backend which is hosted in the AWS EC2 due to billing issues, If you want, you can run the application locally)
Let's have a look, how you can deploy this on your local machine.
Get a clone from this repository and go to convert-time-zone-frontend folder. Required: Node.js in your machine.
Install all the node modules to your project.
npm install
After succesfully installed all the node modules, can run the project project using following command.
npm run serve
If need to deploy the frontend to any other platform, use this command.
npm run build
The frontend project will run on : http://localhost:8080
Get a clone from this repository and go to convert-time-zone-backend folder. Required : python3
To install all the libraries which you need, run the following command.
pip3 install -r requirements.txt
Following command will run the server.py file.
python server.py
The backend project will run on url: http://localhost:3000
Below image shows the time zone converter application which is developed and deployed.