✨ ParseDate should handle DateFormat
This commit is contained in:
		
					parent
					
						
							
								44e79916d3
							
						
					
				
			
			
				commit
				
					
						391452e3d9
					
				
			
		
					 6 changed files with 17 additions and 940 deletions
				
			
		|  | @ -7,6 +7,8 @@ import ( | |||
| 	"github.com/markusmobius/go-dateparser/date" | ||||
| ) | ||||
| 
 | ||||
| const DateFormat = "January 02, 2006 at 03:04:05PM -0700" | ||||
| 
 | ||||
| // These are somewhat arbitrary, but reasonably useful min and max times | ||||
| var ( | ||||
| 	MinTime = time.Unix(-2208988800, 0) // Jan 1, 1900 | ||||
|  | @ -21,12 +23,16 @@ func ParseDate(in string) (t time.Time, err error) { | |||
| 		return MaxTime, nil | ||||
| 	} | ||||
| 
 | ||||
| 	d, err := dp.Parse(&dp.Configuration{ | ||||
| 	conf := dp.Configuration{ | ||||
| 		CurrentTime:        time.Now().Local(), | ||||
| 		ReturnTimeAsPeriod: true, | ||||
| 	}, in) | ||||
| 	} | ||||
| 
 | ||||
| 	d, err := dp.Parse(&conf, in) | ||||
| 	t = d.Time | ||||
| 	if err != nil { | ||||
| 		d, err = dp.Parse(&conf, in, DateFormat) | ||||
| 		t = d.Time | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue