aboutsummaryrefslogtreecommitdiff
path: root/src/components/Clock.tsx
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2024-05-12 18:04:15 +0530
committerAkshay Nair <phenax5@gmail.com>2024-09-29 16:16:38 +0530
commitd87cea9ff2467f93be28533938dfc3a3e5c0c937 (patch)
treef4990814079a2fcaab7906c740ba04add28fa9e5 /src/components/Clock.tsx
parent8995438b9a8649d30d870826d0f8fbf283d68933 (diff)
downloaddaft-launcher-d87cea9ff2467f93be28533938dfc3a3e5c0c937.tar.gz
daft-launcher-d87cea9ff2467f93be28533938dfc3a3e5c0c937.zip
Add home and clock on top
Diffstat (limited to 'src/components/Clock.tsx')
-rw-r--r--src/components/Clock.tsx37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/components/Clock.tsx b/src/components/Clock.tsx
new file mode 100644
index 0000000..113201f
--- /dev/null
+++ b/src/components/Clock.tsx
@@ -0,0 +1,37 @@
+import React, {useEffect, useMemo, useState} from 'react';
+import {Text, View} from 'react-native';
+
+export const Clock: React.FC = () => {
+ const [date, setDate] = useState(() => new Date());
+ useEffect(() => {
+ const interval = setInterval(() => {
+ setDate(new Date());
+ }, 5000);
+ return () => clearInterval(interval);
+ }, []);
+
+ const timeText = useMemo(() => {
+ const formatter = new Intl.DateTimeFormat('en', {
+ hour: 'numeric',
+ minute: 'numeric',
+ second: 'numeric',
+ });
+ return formatter.format(date);
+ }, [date]);
+
+ const dateText = useMemo(() => {
+ const formatter = new Intl.DateTimeFormat('en-IN', {
+ month: 'short',
+ day: 'numeric',
+ weekday: 'long',
+ });
+ return formatter.format(date);
+ }, [date]);
+
+ return (
+ <View className="p-6">
+ <Text className="text-3xl font-bold">{timeText}</Text>
+ <Text className="text-lg">{dateText}</Text>
+ </View>
+ );
+};