Skip to content

Commit

Permalink
feat: display nepali date and time (basic)
Browse files Browse the repository at this point in the history
  • Loading branch information
aj3sh committed Aug 30, 2024
1 parent ce637bd commit a5b5ca4
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 47 deletions.
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine": "auto",
"printWidth": 88,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false
}
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<title>NepaliTime</title>
</head>
<body>
<div id="root"></div>
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"preview": "vite preview"
},
"dependencies": {
"dayjs": "^1.11.13",
"nepali-datetime": "^1.2.1",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
82 changes: 58 additions & 24 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,42 +1,76 @@
@import url('https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&family=Mukta:wght@200;300;400;500;600;700;800&display=swap');

.font-mukta {
font-family: 'Mukta', sans-serif;
}

.font-montserrat {
font-family: 'Montserrat', sans-serif;
}

.text-right {
text-align: right;
}

#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
.english-date {
font-size: 16px;
}

.nepali-date {
font-size: 40px;
}

.nepali-time {
font-size: 50px;
display: flex;
}

.nepali-hour,
.nepali-minute {
margin-right: 15px;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);

.nepali-hour::after,
.nepali-minute::after {
content: ':';
position: absolute;
right: -20px;
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);

.nepali-time .nepali-time-sub {
position: relative;
display: inline-block;
width: 85px;
letter-spacing: 10px;
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
.nepali-am-pm {
margin-left: 5px;
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
.org-name {
position: absolute;
width: 100%;
text-align: center;
left: 0;
bottom: 10px;
color: #666;
font-weight: 300;
}

.card {
padding: 2em;
.org-name a {
color: #666;
font-weight: 300;
text-decoration: underline;
}

.read-the-docs {
color: #888;
.org-name a:hover {
color: #666;
}
71 changes: 49 additions & 22 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,60 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import { useCallback, useEffect, useState } from 'react'
import dayjs from 'dayjs'
import NepaliDate from 'nepali-datetime'

import './App.css'

function App() {
const [count, setCount] = useState(0)
const [npDate, setNpDate] = useState('')
const [enDate, setEnDate] = useState('')

const [npHour, setNPHour] = useState('')
const [npMinute, setNPMinute] = useState('')
const [npSecond, setNPSecond] = useState('')
const [npAmPm, setNPAmPm] = useState('')

const updateTime = useCallback(() => {
const currentNepaliDateTime = new NepaliDate()
setNpDate(currentNepaliDateTime.formatNepali('MMMM DD, YYYY'))
setEnDate(dayjs().format('MMMM DD, YYYY'))

setNPHour(currentNepaliDateTime.format('hh'))
setNPMinute(currentNepaliDateTime.format('mm'))
setNPSecond(currentNepaliDateTime.format('ss'))
setNPAmPm(currentNepaliDateTime.format('A'))
}, [])

useEffect(() => {
updateTime()
const updateTimeInterval = setInterval(updateTime, 1000)
return () => clearInterval(updateTimeInterval)
}, [updateTime])

return (
<>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
<div className="time-board">
<div className="font-montserrat english-date">
<span>{enDate}</span>
</div>
<div className="nepali-date font-mukta">
<span>{npDate}</span>
</div>
<div className="nepali-time font-montserrat">
<span className="nepali-time-sub nepali-hour">{npHour}</span>
<span className="nepali-time-sub nepali-minute">{npMinute}</span>
<span className="nepali-time-sub nepali-second">{npSecond}</span>
<span className="nepali-am-pm">{npAmPm}</span>
</div>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
<div className="org-name font-montserrat">
Powered by{' '}
<a
target="_blank"
href="https://github.com/opensource-nepal/node-nepali-datetime"
>
node-nepali-datetime
</a>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
}
Expand Down

0 comments on commit a5b5ca4

Please sign in to comment.