當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Time.FixedZone函數代碼示例

本文整理匯總了Golang中Time.FixedZone函數的典型用法代碼示例。如果您正苦於以下問題:Golang FixedZone函數的具體用法?Golang FixedZone怎麽用?Golang FixedZone使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了FixedZone函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestTimestampRoundtrip

func TestTimestampRoundtrip(t *testing.T) {
	defer leaktest.AfterTest(t)()
	ts := time.Date(2006, 7, 8, 0, 0, 0, 123000, time.FixedZone("UTC", 0))

	parse := func(encoded []byte) time.Time {
		decoded, err := parseTs(string(encoded))
		if err != nil {
			t.Fatal(err)
		}
		return decoded.UTC()
	}

	if actual := parse(formatTs(ts, nil, nil)); !ts.Equal(actual) {
		t.Fatalf("timestamp did not roundtrip got [%s] expected [%s]", actual, ts)
	}

	// Also check with a 0, positive, and negative offset.
	CET := time.FixedZone("Europe/Paris", 0)
	EST := time.FixedZone("America/New_York", 0)

	for _, tz := range []*time.Location{time.UTC, CET, EST} {
		if actual := parse(formatTs(ts, tz, nil)); !ts.Equal(actual) {
			t.Fatalf("[%s]: timestamp did not roundtrip got [%s] expected [%s]", tz, actual, ts)
		}
	}
}
開發者ID:hvaara,項目名稱:cockroach,代碼行數:26,代碼來源:types_test.go

示例2: TestDateParsing

func TestDateParsing(t *testing.T) {
	tests := []struct {
		dateStr string
		exp     time.Time
	}{
		// RFC 5322, Appendix A.1.1
		{
			"Fri, 21 Nov 1997 09:55:06 -0600",
			time.Date(1997, 11, 21, 9, 55, 6, 0, time.FixedZone("", -6*60*60)),
		},
		// RFC5322, Appendix A.6.2
		// Obsolete date.
		{
			"21 Nov 97 09:55:06 GMT",
			time.Date(1997, 11, 21, 9, 55, 6, 0, time.FixedZone("GMT", 0)),
		},
	}
	for _, test := range tests {
		hdr := Header{
			"Date": []string{test.dateStr},
		}
		date, err := hdr.Date()
		if err != nil {
			t.Errorf("Failed parsing %q: %v", test.dateStr, err)
			continue
		}
		if !date.Equal(test.exp) {
			t.Errorf("Parse of %q: got %+v, want %+v", test.dateStr, date, test.exp)
		}
	}
}
開發者ID:rgmabs19357,項目名稱:gcc,代碼行數:31,代碼來源:message_test.go

示例3: TestGetTransactions

func TestGetTransactions(t *testing.T) {
	t.Parallel()

	k := Kasse{db: createDB(t), log: testLogger(t)}
	defer k.db.Close()

	mero := User{ID: 1, Name: "Merovius", Password: []byte("password")}
	koebi := User{ID: 2, Name: "Koebi", Password: []byte("password1")}

	insertData(t, k.db, []User{
		mero,
		koebi,
	}, []Card{
		{ID: []byte("aaaa"), User: 1},
		{ID: []byte("aaab"), User: 1},
		{ID: []byte("baaa"), User: 2},
		{ID: []byte("baab"), User: 2},
	}, []Transaction{
		{ID: 1, User: 1, Card: nil, Time: time.Date(2015, 4, 6, 22, 59, 3, 0, time.FixedZone("TST", 3600)), Amount: 1000, Kind: "Aufladung"},
		{ID: 2, User: 1, Card: []byte("aaaa"), Time: time.Date(2015, 4, 6, 23, 5, 27, 0, time.FixedZone("TST", 3600)), Amount: -100, Kind: "Kartenswipe"},
		{ID: 3, User: 1, Card: []byte("aaab"), Time: time.Date(2015, 4, 6, 23, 7, 23, 0, time.FixedZone("TST", 3600)), Amount: -100, Kind: "Kartenswipe"},
	})

	tcs := []struct {
		user    User
		n       int
		wantErr error
		amounts []int
	}{
		{koebi, 0, nil, nil},
		{koebi, 23, nil, nil},
		{mero, 2, nil, []int{-100, -100}},
		{mero, 0, nil, []int{-100, -100, 1000}},
	}

	for _, tc := range tcs {
		got, gotErr := k.GetTransactions(tc.user, tc.n)
		if tc.wantErr != nil {
			if gotErr != tc.wantErr {
				t.Errorf("GetTransactions(%v, %v) == (%v, %v), want (_, %v)", tc.user.Name, tc.n, got, gotErr, tc.wantErr)
			}
			continue
		} else if gotErr != nil {
			t.Errorf("GetTransactions(%v, %v) == (%v, %v), want (_, %v)", tc.user.Name, tc.n, got, gotErr, nil)
			continue
		}

		if len(got) != len(tc.amounts) {
			t.Errorf("GetTransactions(%v, %v) == (%v, %v), want %v", tc.user.Name, tc.n, got, gotErr, tc.amounts)
			continue
		}

		for i := range got {
			if got[i].Amount != tc.amounts[i] {
				t.Errorf("GetTransactions(%v, %v) == (%v, %v), want %v", tc.user.Name, tc.n, got, gotErr, tc.amounts)
				continue
			}
		}
	}
}
開發者ID:joker234,項目名稱:kasse,代碼行數:60,代碼來源:main_test.go

示例4: convertIPPDateToTime

// convertIPPDateToTime converts an RFC 2579 date to a time.Time object.
func convertIPPDateToTime(date *C.ipp_uchar_t) time.Time {
	r := bytes.NewReader(C.GoBytes(unsafe.Pointer(date), 11))
	var year uint16
	var month, day, hour, min, sec, dsec uint8
	binary.Read(r, binary.BigEndian, &year)
	binary.Read(r, binary.BigEndian, &month)
	binary.Read(r, binary.BigEndian, &day)
	binary.Read(r, binary.BigEndian, &hour)
	binary.Read(r, binary.BigEndian, &min)
	binary.Read(r, binary.BigEndian, &sec)
	binary.Read(r, binary.BigEndian, &dsec)

	var utcDirection, utcHour, utcMin uint8
	binary.Read(r, binary.BigEndian, &utcDirection)
	binary.Read(r, binary.BigEndian, &utcHour)
	binary.Read(r, binary.BigEndian, &utcMin)

	var utcOffset time.Duration
	utcOffset += time.Duration(utcHour) * time.Hour
	utcOffset += time.Duration(utcMin) * time.Minute
	var loc *time.Location
	if utcDirection == '-' {
		loc = time.FixedZone("", -int(utcOffset.Seconds()))
	} else {
		loc = time.FixedZone("", int(utcOffset.Seconds()))
	}

	nsec := int(dsec) * 100 * int(time.Millisecond)

	return time.Date(int(year), time.Month(month), int(day), int(hour), int(min), int(sec), nsec, loc)
}
開發者ID:TechEdge01,項目名稱:cups-connector,代碼行數:32,代碼來源:cups.go

示例5: parseTimeStamp

func (d *decoder) parseTimeStamp(dm *defmsg, fieldv reflect.Value, pfield *field) {
	u32 := dm.arch.Uint32(d.tmp[:fitUint32.size()])
	if u32 == 0xFFFFFFFF {
		return
	}
	if u32 < systemTimeMarker {
		if debug {
			log.Println("parsing time: seconds from device power on")
		}
	}

	if pfield.t == timeutc {
		if pfield.num == fieldNumTimeStamp {
			d.timestamp = u32
			d.lastTimeOffset = int32(d.timestamp & compressedTimeMask)
		}
		t := decodeDateTime(u32)
		fieldv.Set(reflect.ValueOf(t))
		return
	}

	// Local timestamp.
	//
	// TODO(tormoder): Improve. We may have offset from
	// UTC, but getting actual timezone is complex. Could
	// take GPS coordinates into account, but
	// complicated...
	//
	// Update - this actually exists for Go
	// https://github.com/bradfitz/latlong
	//
	// For now use a custom timezone with the calculated
	// offset to indicated that it is not UTC.
	var local time.Time
	switch {
	case d.timestamp == 0, d.timestamp < systemTimeMarker:
		// No time reference.
		// Set local with zero offset.
		d.timestamp = u32
		tzone := time.FixedZone(localZoneName, 0)
		local = decodeDateTime(u32)
		local = local.In(tzone)
	default:
		local = decodeDateTime(u32)
		utc := decodeDateTime(d.timestamp)
		offsetDur := local.Sub(utc)
		tzone := time.FixedZone(localZoneName, int(offsetDur.Seconds()))
		local = utc.In(tzone)
	}
	fieldv.Set(reflect.ValueOf(local))
}
開發者ID:Kyperion,項目名稱:fit,代碼行數:51,代碼來源:reader.go

示例6: TestUnserialize

func TestUnserialize(t *testing.T) {
	cases := []unserializeTest{
		{[]byte(example_packet), HookMessage{
			Before: "5aef35982fb2d34e9d9d4502f6ede1072793222d",
			Repository: Repository{
				URL:         "http://github.com/defunkt/github",
				Name:        "github",
				Description: "You're lookin' at it.",
				Watchers:    5,
				Forks:       2,
				Private:     true,
				Owner: Author{
					Email: "[email protected]",
					Name:  "defunkt",
				},
			},
			Commits: []Commit{
				{
					ID:  "41a212ee83ca127e3c8cf465891ab7216a705f59",
					URL: "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
					Author: Author{
						Email: "[email protected]",
						Name:  "Chris Wanstrath",
					},
					Message:   "okay i give in",
					Timestamp: time.Date(2008, 02, 15, 14, 57, 17, 0, time.FixedZone("", -8*3600)),
					Added:     []string{"filepath.rb"},
				},
				{
					ID:  "de8251ff97ee194a289832576287d6f8ad74e3d0",
					URL: "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
					Author: Author{
						Email: "[email protected]",
						Name:  "Chris Wanstrath",
					},
					Message:   "update pricing a tad",
					Timestamp: time.Date(2008, 02, 15, 14, 36, 34, 0, time.FixedZone("", -8*3600)),
				},
			},
			After: "de8251ff97ee194a289832576287d6f8ad74e3d0",
			Ref:   "refs/heads/master",
		}},
	}

	for _, c := range cases {
		c.perform(t)
	}
}
開發者ID:jbaikge,項目名稱:goci,代碼行數:48,代碼來源:hook_test.go

示例7: TestNewMongoTimestamp

func (s *oplogSuite) TestNewMongoTimestamp(c *gc.C) {
	t := time.Date(2015, 6, 24, 12, 47, 0, 0, time.FixedZone("somewhere", 5*3600))

	expected := bson.MongoTimestamp(6163845091342417920)
	c.Assert(mongo.NewMongoTimestamp(t), gc.Equals, expected)
	c.Assert(mongo.NewMongoTimestamp(t.In(time.UTC)), gc.Equals, expected)
}
開發者ID:makyo,項目名稱:juju,代碼行數:7,代碼來源:oplog_test.go

示例8: Afghanistan

// Afghanistan returns a pointer to time.Location of Asia/Kabul
func Afghanistan() *time.Location {
	loc, err := time.LoadLocation("Asia/Kabul")
	if err != nil {
		loc = time.FixedZone("Asia/Kabul", 16200) // UTC + 04:30
	}
	return loc
}
開發者ID:yaa110,項目名稱:go-persian-calendar,代碼行數:8,代碼來源:ptime.go

示例9: Test_parseLastModified_Normal

func Test_parseLastModified_Normal(t *testing.T) {
	expected := time.Date(2013, time.November, 27, 0, 6, 52, 0, time.FixedZone("-0500", -5*60*60))
	test_string := `2013-11-27T00:06:52-05:00`
	parsed, err := parseLastModified(test_string)
	assert.Nil(t, err, fmt.Sprintf("unexpected error from parseLastModified: %s", err))
	assert.Equal(t, parsed.String(), expected.String(), fmt.Sprintf("parsed item \"%s\" did not match expected \"%s\"", parsed, expected))
}
開發者ID:ThatRubenAguilar,項目名稱:go-sitemaps,代碼行數:7,代碼來源:sitemapparsing_test.go

示例10: reqlTimeToNativeTime

func reqlTimeToNativeTime(timestamp float64, timezone string) (time.Time, error) {
	sec := int64(timestamp)

	t := time.Unix(sec, 0)

	// Caclulate the timezone
	if timezone != "" {
		hours, err := strconv.Atoi(timezone[1:3])
		if err != nil {
			return time.Time{}, err
		}
		minutes, err := strconv.Atoi(timezone[4:6])
		if err != nil {
			return time.Time{}, err
		}
		tzOffset := ((hours * 60) + minutes) * 60
		if timezone[:1] == "-" {
			tzOffset = 0 - tzOffset
		}

		t = t.In(time.FixedZone(timezone, tzOffset))
	}

	return t, nil
}
開發者ID:radioact1ve,項目名稱:gorethink,代碼行數:25,代碼來源:utils.go

示例11: TestUnconfirmedResourcesDontGenerateEvents

func (s *ServiceSuite) TestUnconfirmedResourcesDontGenerateEvents(c *C) {
	data, err := ioutil.ReadFile("fixtures/brad_bradworth_event_source_bundle.json")
	util.CheckErr(err)

	bundle := new(models.Bundle)
	json.Unmarshal(data, bundle)

	// Switch a few resources to be unconfirmed
	bundle.Entry[2].Resource.(*models.Condition).VerificationStatus = "refuted"
	bundle.Entry[4].Resource.(*models.MedicationStatement).Status = "entered-in-error"

	es, err := BundleToEventStream(bundle)
	util.CheckErr(err)

	c.Assert(es.Patient, NotNil)
	c.Assert(es.Patient.Id, Equals, "507f1f77bcf86cd799439001")
	c.Assert(es.Events, HasLen, 3)
	loc := time.FixedZone("-0500", -5*60*60)
	// Event 0 (Condition: Atrial Fibrillation)
	c.Assert(es.Events[0].Date.Equal(time.Date(2012, time.September, 20, 8, 0, 0, 0, loc)), Equals, true)
	c.Assert(es.Events[0].Type, Equals, "Condition")
	c.Assert(es.Events[0].End, Equals, false)
	c.Assert(es.Events[0].Value, DeepEquals, bundle.Entry[1].Resource)
	// Event 1 (Condition: Cerebral infarction due to cerebral artery occlusion)
	c.Assert(es.Events[1].Date.Equal(time.Date(2014, time.January, 17, 20, 35, 0, 0, loc)), Equals, true)
	c.Assert(es.Events[1].Type, Equals, "Condition")
	c.Assert(es.Events[1].End, Equals, false)
	c.Assert(es.Events[1].Value, DeepEquals, bundle.Entry[3].Resource)
	// Event 2 (Condition END: Cerebral infarction due to cerebral artery occlusion)
	c.Assert(es.Events[2].Date.Equal(time.Date(2014, time.January, 17, 20, 40, 0, 0, loc)), Equals, true)
	c.Assert(es.Events[2].Type, Equals, "Condition")
	c.Assert(es.Events[2].End, Equals, true)
	c.Assert(es.Events[2].Value, DeepEquals, bundle.Entry[3].Resource)
}
開發者ID:intervention-engine,項目名稱:riskservice,代碼行數:34,代碼來源:service_test.go

示例12: TestFmtTimeFull

func TestFmtTimeFull(t *testing.T) {

	loc, err := time.LoadLocation("America/Toronto")
	if err != nil {
		t.Errorf("Expected '<nil>' Got '%s'", err)
	}

	fixed := time.FixedZone("OTHER", -4)

	tests := []struct {
		t        time.Time
		expected string
	}{
		{
			t:        time.Date(2016, 02, 03, 9, 5, 1, 0, loc),
			expected: "9:05:01 am Eastern Standard Time",
		},
		{
			t:        time.Date(2016, 02, 03, 20, 5, 1, 0, fixed),
			expected: "8:05:01 pm OTHER",
		},
	}

	trans := New()

	for _, tt := range tests {
		s := trans.FmtTimeFull(tt.t)
		if s != tt.expected {
			t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
		}
	}
}
開發者ID:luizbafilho,項目名稱:fusis,代碼行數:32,代碼來源:en_test.go

示例13: TimeZone

func TimeZone() {
	jst := time.FixedZone("Asia/Tokyo", 9*60*60)
	n1 := time.Now()

	n2 := n1.UTC()
	n3 := n2.In(jst)
	now := time.Date(
		n3.Year(),
		n3.Month(),
		n3.Day(),
		0,
		0,
		0,
		0,
		jst,
	)

	nowUnix := now.Unix()

	tracer.Println("jst:", jst)
	tracer.Println("n1:", n1)           // JST(日本標準時)のためジャストな時間で表示
	tracer.Println("n2:", n2)           // UTC(協定世界時)で表示のため、-9時間
	tracer.Println("n3:", n3)           // Asia/Tokyoに指定した時間、JSTと一緒になる
	tracer.Println("now:", now)         // 実行日の0時
	tracer.Println("nowUnix:", nowUnix) // 1970/01/01 UTC からの経過時間ミリ秒

	prevDay := now.AddDate(0, 0, -1)

	tracer.Println("nowPrevDay:", prevDay)
	tracer.Println("nowPrevDayUnix:", prevDay.Unix()) // 前日の経過時間ミリ秒
}
開發者ID:kitakitabauer,項目名稱:go-sample,代碼行數:31,代碼來源:main.go

示例14: TestParseTs

// The assertions in this test should also be caught by the integration tests on
// various drivers.
func TestParseTs(t *testing.T) {
	defer leaktest.AfterTest(t)()

	var parseTsTests = []struct {
		strTimestamp string
		expected     time.Time
	}{
		// time.RFC3339Nano for github.com/lib/pq.
		{"2006-07-08T00:00:00.000000123Z", time.Date(2006, 7, 8, 0, 0, 0, 123, time.FixedZone("UTC", 0))},

		// The format accepted by pq.ParseTimestamp.
		{"2001-02-03 04:05:06.123-07", time.Date(2001, time.February, 3, 4, 5, 6, 123000000, time.FixedZone("", -7*60*60))},
	}

	for i, test := range parseTsTests {
		parsed, err := parseTs(test.strTimestamp)
		if err != nil {
			t.Errorf("%d could not parse [%s]: %v", i, test.strTimestamp, err)
			continue
		}
		if !parsed.Equal(test.expected) {
			t.Errorf("%d parsing [%s] got [%s] expected [%s]", i, test.strTimestamp, parsed, test.expected)
		}
	}
}
開發者ID:hvaara,項目名稱:cockroach,代碼行數:27,代碼來源:types_test.go

示例15: Process

func (c *UserInfoCommand) Process(args []string, msg *discordgo.Message, info *GuildInfo) (string, bool) {
	if len(args) < 1 {
		return "```You must provide a user to search for.```", false
	}
	arg := strings.Join(args, " ")
	IDs := FindUsername(arg, info)
	if len(IDs) == 0 { // no matches!
		return "```Error: Could not find any usernames or aliases matching " + arg + "!```", false
	}
	if len(IDs) > 1 {
		return "```Could be any of the following users or their aliases:\n" + strings.Join(IDsToUsernames(IDs, info), "\n") + "```", len(IDs) > 5
	}

	aliases := sb.db.GetAliases(IDs[0])
	dbuser, lastseen, tz, _ := sb.db.GetUser(IDs[0])
	localtime := ""
	if tz == nil {
		tz = time.FixedZone("[Not Set]", 0)
	} else {
		localtime = time.Now().In(tz).Format(time.RFC1123)
	}
	m, err := sb.dg.GuildMember(info.Guild.ID, SBitoa(IDs[0]))
	if err != nil {
		m = &discordgo.Member{Roles: []string{}}
		u, err := sb.dg.User(SBitoa(IDs[0]))
		if err != nil {
			if dbuser == nil {
				return "```Error retrieving user information: " + err.Error() + "```", false
			}
			u = dbuser
		}
		m.User = u
	}
	authortz := getTimezone(info, msg.Author)
	joinedat, err := time.Parse(time.RFC3339Nano, m.JoinedAt)
	joined := ""
	if err == nil {
		joined = joinedat.In(authortz).Format(time.RFC1123)
	}
	guildroles, err := sb.dg.GuildRoles(info.Guild.ID)
	if err != nil {
		guildroles = info.Guild.Roles
	}

	roles := make([]string, 0, len(m.Roles))
	for _, v := range m.Roles {
		if err == nil {
			for _, role := range guildroles {
				if role.ID == v {
					roles = append(roles, role.Name)
					break
				}
			}
		} else {
			roles = append(roles, "<@&"+v+">")
		}
	}

	return ExtraSanitize(fmt.Sprintf("**ID:** %v\n**Username:** %v#%v\n**Nickname:** %v\n**Timezone:** %v\n**Local Time:** %v\n**Joined:** %v\n**Roles:** %v\n**Bot:** %v\n**Last Seen:** %v\n**Aliases:** %v\n**Avatar:** ", m.User.ID, m.User.Username, m.User.Discriminator, m.Nick, tz, localtime, joined, strings.Join(roles, ", "), m.User.Bot, lastseen.In(authortz).Format(time.RFC1123), strings.Join(aliases, ", "))) + discordgo.EndpointUserAvatar(m.User.ID, m.User.Avatar), false
}
開發者ID:blackhole12,項目名稱:sweetiebot,代碼行數:60,代碼來源:users_command.go


注:本文中的Time.FixedZone函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。