github.com/sagernet/sing-box@v1.9.0-rc.20/include/tz_ios.go (about)

     1  package include
     2  
     3  /*
     4  #cgo CFLAGS: -x objective-c
     5  #cgo LDFLAGS: -framework Foundation
     6  #import <Foundation/Foundation.h>
     7  const char* getSystemTimeZone() {
     8      NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
     9      NSString *timeZoneName = [timeZone description];
    10      return [timeZoneName UTF8String];
    11  }
    12  */
    13  import "C"
    14  
    15  import (
    16  	"strings"
    17  	"time"
    18  )
    19  
    20  func init() {
    21  	tzDescription := C.GoString(C.getSystemTimeZone())
    22  	if len(tzDescription) == 0 {
    23  		return
    24  	}
    25  	location, err := time.LoadLocation(strings.Split(tzDescription, " ")[0])
    26  	if err != nil {
    27  		return
    28  	}
    29  	time.Local = location
    30  }