timeutil

package
v0.0.0-...-cd8a489 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLocalTimeZone

func SetLocalTimeZone(fitFile *fit.File) error

SetLocalTimeZone use the external library github.com/bradfitz/latlong and available FIT file GPS data (Record, Session or Lap messages) to set the timezone of local timestamps. It processes FIT files of type "Activity" and "ActivitySummary". It currently only attempts to set the local time zone of the field "LocalTimestamp" for the file's "Activity" message. SetLocalTimeZone returns a nil error if a local time zone was set or a descriptive error otherwise.

Example
package main

import (
	"bytes"
	"fmt"
	"os"
	"path/filepath"

	"github.com/JesprUniverse/fit"
	"github.com/JesprUniverse/fit/timeutil"
)

func main() {
	testFile := filepath.Join("../testdata", "fitsdk", "Activity.fit")
	testData, err := os.ReadFile(testFile)
	if err != nil {
		fmt.Println(err)
		return
	}

	fit, err := fit.Decode(bytes.NewReader(testData))
	if err != nil {
		fmt.Println(err)
		return
	}

	activity, err := fit.Activity()
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Post decode & pre SetLocalTimezone:")
	fmt.Println(activity.Activity.LocalTimestamp)
	err = timeutil.SetLocalTimeZone(fit)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("Post SetLocalTimezone:")
	fmt.Println(activity.Activity.LocalTimestamp)

}
Output:

Post decode & pre SetLocalTimezone:
2012-04-09 17:24:51 -0400 FITLOCAL
Post SetLocalTimezone:
2012-04-09 17:24:51 -0400 EDT

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL