Esempio n. 1
0
func setClock(t time.Time) error {
	tv := syscall.NsecToTimeval(t.UnixNano())
	if err := syscall.Settimeofday(&tv); err != nil {
		return errors.New("settimeofday: " + err.Error())
	}
	return nil
}
Esempio n. 2
0
func main() {
	switch len(flag.Args()) {
	case 0:
		fmt.Printf("%v\n", date(z))
	case 1:
		argv0 := flag.Args()[0]
		if argv0[0] == '+' {
			fmt.Printf("%v\n", dateMap(argv0[1:]))
		} else {
			t, err := getTime(argv0)
			if err != nil {
				log.Fatalf("%v: %v", argv0, err)
			}
			tv := syscall.NsecToTimeval(t.UnixNano())
			if err := syscall.Settimeofday(&tv); err != nil {
				log.Fatalf("%v: %v", argv0, err)
			}
		}
	default:
		usage()
	}
}
Esempio n. 3
0
File: main.go Progetto: zyxar/berry
func main() {
	flag.Parse()
	if !*readTime && !*setTime && !*writeTime {
		flag.Usage()
		return
	}
	var err error
	if i, err = bus.NewI2C(*addr, *dev); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(2)
	}
	if *readTime {
		if t := getDateDS1307(); t != nil {
			fmt.Println(t)
		}
	}
	if *setTime {
		if t := getDateDS1307(); t != nil {
			tv := syscall.Timeval{
				Sec:  int32(t.Unix()),
				Usec: int32(t.UnixNano() % 100000000),
			}
			if err = syscall.Settimeofday(&tv); err != nil {
				fmt.Fprintln(os.Stderr, err.Error())
			}
		}
	}
	if *writeTime {
		now := time.Now()
		fmt.Println("set time -", now)
		setDateDS1307(&now)
		time.Sleep(100 * time.Millisecond)
		if t := getDateDS1307(); t != nil {
			fmt.Println(t)
		}
	}
}