mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-11-04 08:20:58 +00:00 
			
		
		
		
	Merge pull request #771 from benphelps/datetime-locale
Feature: allow setting locale for datetime widget directly
This commit is contained in:
		
						commit
						1fd198c255
					
				@ -13,17 +13,18 @@ const textSizes = {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function DateTime({ options }) {
 | 
					export default function DateTime({ options }) {
 | 
				
			||||||
  const { text_size: textSize, format } = options;
 | 
					  const { text_size: textSize, locale, format } = options;
 | 
				
			||||||
  const { i18n } = useTranslation();
 | 
					  const { i18n } = useTranslation();
 | 
				
			||||||
  const [date, setDate] = useState("");
 | 
					  const [date, setDate] = useState("");
 | 
				
			||||||
 | 
					  const dateLocale = locale ?? i18n.language;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  useEffect(() => {
 | 
					  useEffect(() => {
 | 
				
			||||||
    const dateFormat = new Intl.DateTimeFormat(i18n.language, { ...format });
 | 
					    const dateFormat = new Intl.DateTimeFormat(dateLocale, { ...format });
 | 
				
			||||||
    const interval = setInterval(() => {
 | 
					    const interval = setInterval(() => {
 | 
				
			||||||
      setDate(dateFormat.format(new Date()));
 | 
					      setDate(dateFormat.format(new Date()));
 | 
				
			||||||
    }, 1000);
 | 
					    }, 1000);
 | 
				
			||||||
    return () => clearInterval(interval);
 | 
					    return () => clearInterval(interval);
 | 
				
			||||||
  }, [date, setDate, i18n.language, format]);
 | 
					  }, [date, setDate, dateLocale, format]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div className="flex flex-col justify-center first:ml-0 ml-4">
 | 
					    <div className="flex flex-col justify-center first:ml-0 ml-4">
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user