All Projects → snabb → isoweek

snabb / isoweek

Licence: MIT License
Go package for calculating a start date and time of ISO 8601 week. (golang)

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to isoweek

shamsi date
A Flutter and Dart package for using Jalali (Shamsi, Solar, Persian or Jalaali) calendar. You can convert, format and manipulate Jalali and Gregorian (Miladi) date and times.
Stars: ✭ 59 (+84.38%)
Mutual labels:  date, calendar, julian
Xk Time
xk-time 是时间转换,时间计算,时间格式化,时间解析,日历,时间cron表达式和时间NLP等的工具,使用Java8,线程安全,简单易用,多达70几种常用日期格式化模板,支持Java8时间类和Date,轻量级,无第三方依赖。
Stars: ✭ 162 (+406.25%)
Mutual labels:  date, calendar
Time
Building a better date/time library for Swift
Stars: ✭ 1,983 (+6096.88%)
Mutual labels:  date, calendar
Dpicker
A framework-agnostic minimal date picker
Stars: ✭ 187 (+484.38%)
Mutual labels:  date, calendar
Calendar
📆 calendar 日历
Stars: ✭ 119 (+271.88%)
Mutual labels:  date, calendar
React Calendar
Ultimate calendar for your React app.
Stars: ✭ 2,082 (+6406.25%)
Mutual labels:  date, calendar
Date
A date and time library based on the C++11/14/17 <chrono> header
Stars: ✭ 2,389 (+7365.63%)
Mutual labels:  date, calendar
Jkcalendar
Calendar library for iOS
Stars: ✭ 83 (+159.38%)
Mutual labels:  date, calendar
Calendarview
A highly customizable calendar library for Android, powered by RecyclerView.
Stars: ✭ 2,862 (+8843.75%)
Mutual labels:  date, calendar
iso8601
A fast ISO8601 date parser for Go
Stars: ✭ 122 (+281.25%)
Mutual labels:  date, iso8601
duration
Parse iso8601 duration strings, and use to shift dates/times.
Stars: ✭ 51 (+59.38%)
Mutual labels:  date, iso8601
Chrono
Date and time library for Rust
Stars: ✭ 1,780 (+5462.5%)
Mutual labels:  date, calendar
Calendar
📅 PHP Date & Time library that solves common problems in object oriented, immutable way.
Stars: ✭ 113 (+253.13%)
Mutual labels:  date, calendar
Tail.datetime
A lightweight, translat- and configurable Open Source DateTime Picker, written in pure vanilla JavaScript!
Stars: ✭ 139 (+334.38%)
Mutual labels:  date, calendar
Ummalqura Calendar
Implementation of java.util.Calendar for the Umm Al-Qura calendar system.
Stars: ✭ 104 (+225%)
Mutual labels:  date, calendar
Things Calendar
Simple but elegant datepicker for the web — inspired by Things for mac
Stars: ✭ 165 (+415.63%)
Mutual labels:  date, calendar
Dategrid
A customizable swiftui calendar
Stars: ✭ 71 (+121.88%)
Mutual labels:  date, calendar
React Datetimerange Picker
A datetime range picker for your React app.
Stars: ✭ 82 (+156.25%)
Mutual labels:  date, calendar
Datepicker
Get a date with JavaScript! A datepicker with no dependencies.
Stars: ✭ 212 (+562.5%)
Mutual labels:  date, calendar
js-calendar
The lightest Javascript calendar out there, without any dependency.
Stars: ✭ 37 (+15.63%)
Mutual labels:  date, calendar

isoweek

Go Reference Build Status codecov Go Report Card

The Go package isoweek calculates a starting date and time of ISO 8601 week.

ISO 8601 standard defines the common week numbering system used in Europe and many other countries. Monday is the first day of a week.

The Go standard library "time" package has ISOWeek() function for getting ISO 8601 week number of a given Time, but there is no reverse functionality for getting a date from a week number. This package implements that.

Invalid input is silently accepted. There is a separate Validate() function if week number validation is needed.

There are also functions for working with Julian day numbers. Using Julian day numbers is often the easiest and fastest way to do date calculations.

This package does not work with the week system used in US/Canada/Australia (weeks starting on Sundays). However the Julian day number functions may be still useful.

Documentation

https://pkg.go.dev/github.com/snabb/isoweek

Examples

Using weeks with Go standard time.Time

A simple example which gets the starting time of the 1st week of 1985:

	t := isoweek.StartTime(1985, 1, time.UTC)
	fmt.Println(t)
	// Output: 1984-12-31 00:00:00 +0000 UTC

The returned time may be within a previous year as can be seen above.

The AddDate() function in Go standard library "time" package can be used for getting the Time at the end of the week or for iterating through weeks:

	t = t.AddDate(0, 0, 7)
	fmt.Println(t)
	// Output: 1985-01-07 00:00:00 +0000 UTC

	wyear, week := t.ISOWeek()
	fmt.Println(wyear, week)
	// Output: 1985 2

Using weeks, dates and Julian day numbers

The same as above without using Go standard library "time" package:

	y, m, d := isoweek.StartDate(1985, 1)
	fmt.Println(y, m, d)
	// Output: 1984 December 31

	jul := isoweek.DateToJulian(y, m, d)
	jul = jul + 7 // next week
	y, m, d = isoweek.JulianToDate(jul)
	fmt.Println(y, m, d)
	// Output: 1985 January 7

	wyear, week := isoweek.FromDate(y, m, d)
	fmt.Println(wyear, week)
	// Output: 1985 2

Repository

https://github.com/snabb/isoweek

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].