Exemplo n.º 1
0
func parseSleep(line []string) (Sleep, error) {
	sleep := Sleep{}
	if line[0] != "" {
		t, err := util.ParseTime(line[0])
		if err != nil {
			return sleep, err
		}
		sleep.From = t
	}

	if line[1] != "" {
		t, err := util.ParseTime(line[1])
		if err != nil {
			return sleep, err
		}
		sleep.Till = t
	}

	if line[2] != "" {
		d, err := time.ParseDuration(line[2] + "s")
		if err != nil {
			return sleep, err
		}
		sleep.Light = d
	}

	if line[3] != "" {
		d, err := time.ParseDuration(line[3] + "s")
		if err != nil {
			return sleep, err
		}
		sleep.Deep = d
	}

	if line[4] != "" {
		d, err := time.ParseDuration(line[4] + "s")
		if err != nil {
			return sleep, err
		}
		sleep.Rem = d
	}

	if line[5] != "" {
		d, err := time.ParseDuration(line[5] + "s")
		if err != nil {
			return sleep, err
		}
		sleep.Awake = d
	}

	if line[6] != "" {
		w, err := strconv.Atoi(line[6])
		if err != nil {
			return sleep, err
		}
		sleep.Wakeups = w
	}

	return sleep, nil
}
Exemplo n.º 2
0
func parseWeight(line []string) (Weight, error) {
	weight := Weight{}

	if line[0] != "" {
		t, err := util.ParseTime(line[0])
		if err != nil {
			return weight, err
		}
		weight.Time = t
	}

	if line[1] != "" {
		w, err := strconv.ParseFloat(line[1], 64)
		if err != nil {
			return weight, err
		}
		weight.Weight = w
	}

	if line[2] != "" {
		fat, err := strconv.ParseFloat(line[2], 64)
		if err != nil {
			return weight, err
		}
		weight.Fat = fat
	}

	if line[4] != "" {
		weight.Comment = line[4]
	}

	return weight, nil
}