当前位置: 首页>>代码示例>>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;未经允许,请勿转载。