| 
									
										
										
										
											2023-01-03 11:55:46 -08:00
										 |  |  | // Copyright 2020 Signal Messenger, LLC
 | 
					
						
							| 
									
										
										
										
											2020-10-30 15:34:04 -05:00
										 |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-28 18:46:31 -05:00
										 |  |  | import * as React from 'react'; | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { Moment } from 'moment'; | 
					
						
							|  |  |  | import moment from 'moment'; | 
					
						
							| 
									
										
										
										
											2020-09-28 18:46:31 -05:00
										 |  |  | import { isLinkPreviewDateValid } from '../../linkPreviews/isLinkPreviewDateValid'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 12:07:05 -06:00
										 |  |  | type Props = { | 
					
						
							| 
									
										
										
										
											2021-06-25 12:08:16 -04:00
										 |  |  |   date?: null | number; | 
					
						
							| 
									
										
										
										
											2020-09-28 18:46:31 -05:00
										 |  |  |   className?: string; | 
					
						
							| 
									
										
										
										
											2021-01-14 12:07:05 -06:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-09-28 18:46:31 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function LinkPreviewDate({ | 
					
						
							| 
									
										
										
										
											2020-09-28 18:46:31 -05:00
										 |  |  |   date, | 
					
						
							|  |  |  |   className = '', | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | }: Props): JSX.Element | null { | 
					
						
							| 
									
										
										
										
											2020-09-28 18:46:31 -05:00
										 |  |  |   const dateMoment: Moment | null = isLinkPreviewDateValid(date) | 
					
						
							|  |  |  |     ? moment(date) | 
					
						
							|  |  |  |     : null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return dateMoment ? ( | 
					
						
							|  |  |  |     <time className={className} dateTime={dateMoment.toISOString()}> | 
					
						
							|  |  |  |       {dateMoment.format('ll')} | 
					
						
							|  |  |  |     </time> | 
					
						
							|  |  |  |   ) : null; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } |