| 
									
										
										
										
											2021-08-05 07:35:33 -05:00
										 |  |  | // Copyright 2021 Signal Messenger, LLC
 | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import moment from 'moment'; | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { LocalizerType } from '../types/Util'; | 
					
						
							| 
									
										
										
										
											2021-08-05 07:35:33 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Returns something like "Muted until 6:09 PM", localized. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Shouldn't be called with `0`. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export function getMutedUntilText( | 
					
						
							|  |  |  |   muteExpiresAt: number, | 
					
						
							|  |  |  |   i18n: LocalizerType | 
					
						
							|  |  |  | ): string { | 
					
						
							|  |  |  |   if (Number(muteExpiresAt) >= Number.MAX_SAFE_INTEGER) { | 
					
						
							|  |  |  |     return i18n('muteExpirationLabelAlways'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const expires = moment(muteExpiresAt); | 
					
						
							|  |  |  |   const muteExpirationUntil = moment().isSame(expires, 'day') | 
					
						
							|  |  |  |     ? expires.format('LT') | 
					
						
							|  |  |  |     : expires.format('L, LT'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return i18n('muteExpirationLabel', [muteExpirationUntil]); | 
					
						
							|  |  |  | } |