| 
									
										
										
										
											2023-04-01 18:56:42 -07:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2021-03-24 10:55:33 +01:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module TimeRemaining | 
					
						
							|  |  |  |   refine Time do | 
					
						
							|  |  |  |     def remaining | 
					
						
							| 
									
										
										
										
											2023-04-01 18:56:42 -07:00
										 |  |  |       T.bind(self, Time) | 
					
						
							| 
									
										
										
										
											2021-03-24 10:55:33 +01:00
										 |  |  |       [0, self - Time.now].max | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def remaining! | 
					
						
							|  |  |  |       r = remaining | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-01 18:56:42 -07:00
										 |  |  |       Kernel.raise Timeout::Error if r <= 0
 | 
					
						
							| 
									
										
										
										
											2021-03-24 10:55:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       r | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2023-02-07 00:38:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class Time | 
					
						
							|  |  |  |   # Backwards compatibility for formulae that used this ActiveSupport extension | 
					
						
							|  |  |  |   alias rfc3339 xmlschema | 
					
						
							|  |  |  | end |