| 
									
										
										
										
											2023-09-06 18:46:09 -05:00
										 |  |  | package utils | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2023-09-08 15:24:40 -05:00
										 |  |  | 	"errors" | 
					
						
							| 
									
										
										
										
											2023-09-06 18:46:09 -05:00
										 |  |  | 	"fmt" | 
					
						
							|  |  |  | 	p "path" | 
					
						
							| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | 	"strings" | 
					
						
							|  |  |  | 	t "time" | 
					
						
							| 
									
										
										
										
											2023-09-06 18:46:09 -05:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func GetShortPath(path string) string { | 
					
						
							|  |  |  | 	base := p.Base(path) | 
					
						
							|  |  |  | 	dir := p.Dir(path) | 
					
						
							|  |  |  | 	dir = p.Base(dir) | 
					
						
							|  |  |  | 	return fmt.Sprintf("%s/%s", dir, base) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-08 15:24:40 -05:00
										 |  |  | func HourMinSecToSeconds(time string) (float64, error) { | 
					
						
							| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | 	parts := strings.Split(time, ":") | 
					
						
							| 
									
										
										
										
											2023-09-08 15:24:40 -05:00
										 |  |  | 	if len(parts) > 3 { | 
					
						
							|  |  |  | 		return 0, errors.New(fmt.Sprintf("Can't parse %s. Must be in HH:MM:SS format", time)) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | 	units := []string{"h", "m", "s"} | 
					
						
							|  |  |  | 	units = units[len(units)-len(parts):] | 
					
						
							|  |  |  | 	f := "" | 
					
						
							|  |  |  | 	for idx, part := range parts { | 
					
						
							|  |  |  | 		f = f + part + units[idx] | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	dur, _ := t.ParseDuration(f) | 
					
						
							| 
									
										
										
										
											2023-09-08 15:24:40 -05:00
										 |  |  | 	return dur.Seconds(), nil | 
					
						
							| 
									
										
										
										
											2023-09-07 11:00:16 -05:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-09-24 22:34:30 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | func Tern[V any](choice bool, one, two V) V { | 
					
						
							|  |  |  | 	if choice { | 
					
						
							|  |  |  | 		return one | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return two | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-10-29 11:58:00 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | func TernCall[V any](choice bool, one, two func() V) V { | 
					
						
							|  |  |  | 	if choice { | 
					
						
							|  |  |  | 		return one() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return two() | 
					
						
							|  |  |  | } |