Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify calendar format #19

Open
cblp opened this issue Jul 2, 2018 · 0 comments
Open

Specify calendar format #19

cblp opened this issue Jul 2, 2018 · 0 comments
Assignees

Comments

@cblp
Copy link
Collaborator

cblp commented Jul 2, 2018

Variable-precision timestamps have the MMDHmSssnn format. Ten Base64 chars encode months-since-epoch, days, hours, minutes, seconds, milliseconds and an additional sequence number. The resulting resolution is ~4mln timestamps per second, which is often excessive. It is OK to shorten timestamps by zeroing the tail (sequence number, milliseconds, etc). For example, 1CQAneD is 7 chars and 1CQAn is 5 chars (MMDHm, no seconds - Fri May 27 20:50:00 UTC 2016).
We use Gregorian calendar and not milliseconds-since-epoch because Swarm timestamps are hybrid (logical, calendar-aware). Intuitive understanding of timestamps is more important for us than easy calculation of time intervals. The resulting bit loss is tolerable (no month is 64 days long).

значение последних 4 знаков поменялось - в go это сотни наносекунд, для совместимости с RFC4122:
MMDhmsnnnn

actual format is specified by the Go implementation:

func DecodeCalendar(v uint64) time.Time {
	var ns100 int = int(v & MASK24)
	v >>= 24
	var secs int = int(v & 63)
	v >>= 6
	var mins int = int(v & 63)
	v >>= 6
	var hours int = int(v & 63)
	v >>= 6
	var days int = int(v & 63)
	v >>= 6
	var months int = int(v & 4095)
	var month = months % 12
	var year = months / 12
	t := time.Date(year+2010, time.Month(month+1), days+1, hours, mins, secs, ns100*100, time.UTC)
	return t
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants