- Live Demo
- Description
- Features
- Installation
- Usage
- File Structure
- Future Work
- Challenges and Lessons Learned
- Contributing
You can check out the live demo of the application here: Live Demo Link.
World Clock is a web application that displays the current time in various time zones across the world. It uses Moment.js for accurate time zone conversions and formatting.
- Dynamic Time Zone Selection: Users can select from a variety of time zones to view the current time in different cities.
- Automatic Local Time Display: On page load, the application automatically displays the local time based on the user's geolocation.
- Theme Switching: The application features a dynamic theme that switches between 'day' and 'night' modes based on the local time.
- Customizable Time Panels: Users can view and customize multiple time panels for different locations simultaneously.
No special installation steps are required. The application is built with HTML, CSS, and vanilla JavaScript. Simply clone or download the repository and open index.html
in a web browser.
- Open the Application: Open
index.html
in a web browser. - Select Time Zone: Use the dropdown menu to select different time zones and view their corresponding times.
- View Local Time: By default, your local time is displayed upon loading the application.
index.html
: The main HTML file.styles.css
: Contains all the styling for the application.main.js
: Main JavaScript file containing the application logic.timeZoneData.js
: Contains data mapping for time zones and their corresponding city names.
- Additional Time Zone Data: Expanding the list of available time zones.
- Customizable Panel Count: Implementing a feature that allows users to select the number of time panels displayed (up to four). This feature is currently under development in a separate branch.
- Mobile Responsiveness: Enhancing the user interface for better responsiveness on mobile devices.
One of the core challenges of the World Clock project was handling accurate time zone conversion. Utilizing Moment.js and Moment Timezone significantly aided in managing and converting time zones. However, curating the timeZoneData
required meticulous attention to ensure that each time zone was correctly mapped to its corresponding city and country name. The following snippet from timeZoneData.js
highlights this mapping:
export const timeZoneData = {
"Europe/London": "London, GBR",
"Asia/Tokyo": "Tokyo, JPN",
// more mappings...
};
Ensuring that the user interface dynamically reflects changes in theme and time zone selections presented a unique challenge. This required implementing a reactive system to update the UI based on user interactions and time changes. A key part of this was the setTheme
function, which dynamically adjusted the theme based on the local time:
function setTheme() {
let localTimeAmPM;
try {
localTimeAmPM = moment().format("A");
} catch (error) {
console.error(`Error formatting Time for Theme: ${error.message}`);
}
const themeElements = getThemeElements();
if (!themeElements) {
console.error("Failed to set theme due to missing elements.");
return;
}
if (themeElements.bodyElement.classList.contains("default-body")) {
themeElements.bodyElement.classList.remove("default-body");
themeElements.mainElement.classList.remove("default-main");
themeElements.locationSelectElement.classList.remove("default-select");
}
if (themeElements["bodyElement"].classList.contains("day-theme-body")) {
removeThemeClasses(themeElements, "day");
} else if (
themeElements["bodyElement"].classList.contains("night-theme-body")
) {
removeThemeClasses(themeElements, "night");
}
if (localTimeAmPM === "AM") {
addThemeClasses(themeElements, "day");
} else {
addThemeClasses(themeElements, "night");
}
}
The application currently experiences a subtle delay during loading. This issue arises from the way time zone data is processed and the extensive number of DOM manipulations required during the initialization phase. Efforts to address these challenges are ongoing. Future iterations will focus on optimizing data handling and reducing initial render time to enhance user experience. This includes exploring more efficient ways to manage DOM updates and considering lazy loading techniques for time zone data.
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository
- Create a new branch:
git checkout -b new-feature
- Commit your changes:
git commit -m 'Add some feature'
- Push to the branch:
git push origin new-feature
- Create a new Pull Request