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

feat(digital-clock): add digital clock with modern UI #666

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions 33-Digital-Clock/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Advanced UI/UX Digital Clock

![Digital Clock Screenshot](https://github.com/user-attachments/assets/d533e26e-ba79-4133-9e59-5dd60da46acf)

An elegant and feature-rich digital clock web application built with HTML, CSS, and JavaScript. This project demonstrates modern web development techniques and UI/UX principles.

## Features

- Real-time display of current time and date
- Dynamic greeting based on the time of day
- Week number and day of year information
- Light/dark theme toggle
- Responsive design for various device sizes
- Smooth animations and transitions

### Prerequisites

- A modern web browser (Chrome, Firefox, Safari, or Edge)

## Usage

- The clock will automatically display the current time and update every second.
- Click the theme toggle button (🌓) in the top-right corner to switch between light and dark modes.
- The greeting will change based on the time of day (morning, afternoon, evening).
- Additional information such as the current week number and day of year is displayed below the clock.

## Customization

You can easily customize the clock's appearance by modifying the CSS variables in the `<style>` section of the HTML file:

```css
:root {
--primary-color: #3a7bd5;
--secondary-color: #00d2ff;
--text-color: #333;
--bg-color: #f0f4f8;
}
```
32 changes: 32 additions & 0 deletions 33-Digital-Clock/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!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>Advanced UI/UX Digital Clock</title>
</head>

<body>
<button id="theme-toggle">🌓</button>
<div class="clock-container">
<div id="time"></div>
<div id="date"></div>
<div id="greeting"></div>
<div class="info-container">
<div class="info-item">
<div class="info-label">Week</div>
<div id="week" class="info-value"></div>
</div>
<div class="info-item">
<div class="info-label">Day of Year</div>
<div id="day-of-year" class="info-value"></div>
</div>
</div>
</div>

<script src="./script.js"></script>
</body>

</html>
36 changes: 36 additions & 0 deletions 33-Digital-Clock/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function updateClock() {
const now = new Date();
const time = now.toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' });
const date = now.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
const hours = now.getHours();

document.getElementById('time').textContent = time;
document.getElementById('date').textContent = date;

// Greeting based on time of day
let greeting = '';
if (hours < 12) greeting = 'Good morning';
else if (hours < 18) greeting = 'Good afternoon';
else greeting = 'Good evening';
document.getElementById('greeting').textContent = greeting;

// Week number
const weekNumber = Math.ceil((now - new Date(now.getFullYear(), 0, 1)) / 604800000);
document.getElementById('week').textContent = weekNumber;

// Day of year
const start = new Date(now.getFullYear(), 0, 0);
const diff = now - start;
const oneDay = 1000 * 60 * 60 * 24;
const dayOfYear = Math.floor(diff / oneDay);
document.getElementById('day-of-year').textContent = dayOfYear;
}

setInterval(updateClock, 1000);
updateClock(); // Initial call

// Theme toggle functionality
const themeToggle = document.getElementById('theme-toggle');
themeToggle.addEventListener('click', () => {
document.body.classList.toggle('dark-theme');
});
93 changes: 93 additions & 0 deletions 33-Digital-Clock/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap');

:root {
--primary-color: #3a7bd5;
--secondary-color: #00d2ff;
--text-color: #333;
--bg-color: #f0f4f8;
}

body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: 'Roboto', sans-serif;
background-color: var(--bg-color);
transition: background-color 0.3s ease;
}

.clock-container {
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
border-radius: 20px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
padding: 40px;
color: white;
text-align: center;
transition: all 0.3s ease;
}

.clock-container:hover {
transform: translateY(-5px);
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
}

#time {
font-size: 4rem;
font-weight: 700;
margin-bottom: 10px;
}

#date {
font-size: 1.2rem;
font-weight: 300;
margin-bottom: 20px;
}

#greeting {
font-size: 1.5rem;
font-weight: 400;
margin-bottom: 20px;
}

.info-container {
display: flex;
justify-content: space-around;
margin-top: 20px;
}

.info-item {
text-align: center;
}

.info-label {
font-size: 0.9rem;
opacity: 0.8;
}

.info-value {
font-size: 1.2rem;
font-weight: 700;
}

#theme-toggle {
position: absolute;
top: 20px;
right: 20px;
background: none;
border: none;
color: var(--text-color);
font-size: 1.5rem;
cursor: pointer;
transition: transform 0.3s ease;
}

#theme-toggle:hover {
transform: scale(1.1);
}

.dark-theme {
--bg-color: #1a1a2e;
--text-color: #ffffff;
}