LLFYL4PV3LPUZNL2SPVF6FA7WMZSGHSGB4YWS3OUWPARECWI737QC t.Run("should extract file modification time", func(t *testing.T) {path := createTestWAVFile(t, tmpDir, "test_modtime.wav", struct {duration float64sampleRate intchannels intbitsPerSample intcomment stringartist string}{duration: 5.0,sampleRate: 44100,channels: 1,bitsPerSample: 16,comment: "",artist: "",})// Get expected mod timeinfo, err := os.Stat(path)if err != nil {t.Fatalf("Failed to stat file: %v", err)}expectedModTime := info.ModTime()metadata, err := ParseWAVHeader(path)if err != nil {t.Fatalf("Failed to parse WAV header: %v", err)}// Allow 1 second tolerance for filesystem granularitydiff := metadata.FileModTime.Sub(expectedModTime)if diff < -1*time.Second || diff > 1*time.Second {t.Errorf("FileModTime incorrect: got %v, want %v (diff: %v)",metadata.FileModTime, expectedModTime, diff)}// Ensure FileModTime is not zeroif metadata.FileModTime.IsZero() {t.Error("FileModTime should not be zero")}})
Duration float64 // Duration in secondsSampleRate int // Sample rate in HzComment string // Comment from INFO chunk (may contain AudioMoth data)Artist string // Artist from INFO chunkChannels int // Number of audio channelsBitsPerSample int // Bits per sample
Duration float64 // Duration in secondsSampleRate int // Sample rate in HzComment string // Comment from INFO chunk (may contain AudioMoth data)Artist string // Artist from INFO chunkChannels int // Number of audio channelsBitsPerSample int // Bits per sampleFileModTime time.Time // File modification time (fallback timestamp)
if err != nil {return nil, fmt.Errorf("filename timestamp parsing failed: %w", err)}// Apply timezone offsetadjustedTimestamps, err := utils.ApplyTimezoneOffset(filenameTimestamps, location.TimezoneID)if err != nil {return nil, fmt.Errorf("timezone offset application failed: %w", err)
if err == nil {// Only apply timezone if parsing succeededadjustedTimestamps, err := utils.ApplyTimezoneOffset(filenameTimestamps, location.TimezoneID)if err == nil && len(adjustedTimestamps) > 0 {timestampLocal = adjustedTimestamps[0]}// If timezone application fails, continue to file mod time fallback
if len(adjustedTimestamps) > 0 {timestampLocal = adjustedTimestamps[0]}
// If still no timestamp, use file modification time as fallbackif timestampLocal.IsZero() {if !metadata.FileModTime.IsZero() {// Use file mod time (already in system local time)timestampLocal = metadata.FileModTime