All Projects → senseyeio → duration

senseyeio / duration

Licence: other
Parse iso8601 duration strings, and use to shift dates/times.

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to duration

iso8601
A fast ISO8601 date parser for Go
Stars: ✭ 122 (+139.22%)
Mutual labels:  time, date, iso8601
edtf.js
Extended Date Time Format (ISO 8601-2 / EDTF) Parser for JavaScript
Stars: ✭ 44 (-13.73%)
Mutual labels:  time, date, iso8601
Dpicker
A framework-agnostic minimal date picker
Stars: ✭ 187 (+266.67%)
Mutual labels:  time, date
React Native Modal Datetime Picker
A React-Native datetime-picker for Android and iOS
Stars: ✭ 2,412 (+4629.41%)
Mutual labels:  time, date
Swift-ISO8601-DurationParser
Swift ISO8601 Parser
Stars: ✭ 24 (-52.94%)
Mutual labels:  time, iso8601
lit-date
Light-weight, faster datetime formatter for modern browsers.
Stars: ✭ 33 (-35.29%)
Mutual labels:  time, date
Brpickerview
BRPickerView 封装的是iOS中常用的选择器组件,主要包括:日期选择器(支持年月日、年月等15种日期样式选择,支持设置星期、至今等)、地址选择器(支持省市区、省市、省三种地区选择)、自定义字符串选择器(支持单列、多列、二级联动、三级联动选择)。支持自定义主题样式,适配深色模式,支持将选择器组件添加到指定容器视图。
Stars: ✭ 2,149 (+4113.73%)
Mutual labels:  time, date
Jiffy
Jiffy is a Flutter (Android, IOS and Web) date time package inspired by momentjs for parsing, manipulating, querying and formatting dates
Stars: ✭ 238 (+366.67%)
Mutual labels:  time, date
Delorean
Delorean: Time Travel Made Easy
Stars: ✭ 1,793 (+3415.69%)
Mutual labels:  time, date
ptera
Ptera is DateTime library for Deno
Stars: ✭ 62 (+21.57%)
Mutual labels:  time, date
nativescript-datetimepicker
Plugin with date and time picking fields
Stars: ✭ 26 (-49.02%)
Mutual labels:  time, date
SonataTimelineBundle
[Abandoned] Integrates SpyTimelineBundle into Sonata
Stars: ✭ 24 (-52.94%)
Mutual labels:  time, date
Time
Building a better date/time library for Swift
Stars: ✭ 1,983 (+3788.24%)
Mutual labels:  time, date
Gostradamus
Gostradamus: Better DateTimes for Go 🕰️
Stars: ✭ 148 (+190.2%)
Mutual labels:  time, date
Date
A date and time library based on the C++11/14/17 <chrono> header
Stars: ✭ 2,389 (+4584.31%)
Mutual labels:  time, date
Date Picker
📅 Custom responsive date picker widget for Android, written in Kotlin.
Stars: ✭ 146 (+186.27%)
Mutual labels:  time, date
Sonataintlbundle
Symfony SonataIntlBundle
Stars: ✭ 212 (+315.69%)
Mutual labels:  time, date
Moment Range
Fancy date ranges for Moment.js
Stars: ✭ 1,639 (+3113.73%)
Mutual labels:  time, date
Tail.datetime
A lightweight, translat- and configurable Open Source DateTime Picker, written in pure vanilla JavaScript!
Stars: ✭ 139 (+172.55%)
Mutual labels:  time, date
Travel
Framework agnostic PHP package to control the time.
Stars: ✭ 251 (+392.16%)
Mutual labels:  time, date

Duration Build Coverage Go Report Card GoDoc

Parse ISO8601 duration strings, and use to shift dates/times.

Basic Example

package main

import (
	"fmt"
	"time"

	"github.com/senseyeio/duration"
)

func main() {
	d, _ := iso8601.ParseISO8601("P1D")
	today := time.Now()
	tomorrow := d.Shift(today)
	fmt.Println(today.Format("Jan _2"))
	fmt.Println(tomorrow.Format("Jan _2"))
}

Why Does This Package Exist

Why can't we just use a time.Duration and time.Add?

A very reasonable question.

The code below repeatedly adds 24 hours to a time.Time. You might expect the time on that date to stay the same, but there are not always 24 hours in a day. When the clocks change in New York, the time will skew by an hour. As you can see from the output, duration.Duration.Shift() can increment the date without shifting the time.

package main

import (
	"fmt"
	"time"

	"github.com/senseyeio/duration"
)

func main() {
	loc, _ := time.LoadLocation("America/New_York")
	d, _ := iso8601.ParseISO8601("P1D")
	t1, _ := time.ParseInLocation("Jan 2, 2006 at 3:04pm", "Jan 1, 2006 at 3:04pm", loc)
	t2 := t1
	for i := 0; i < 365; i++ {
		t1 = t1.Add(24 * time.Hour)
		t2 = d.Shift(t2)
		fmt.Printf("time.Add:%d    Duration.Shift:%d\n", t1.Hour(), t2.Hour())
	}
}

// Outputs
// time.Add:15    Duration.Shift:15
// time.Add:15    Duration.Shift:15
// time.Add:15    Duration.Shift:15
// ...
// time.Add:16    Duration.Shift:15
// time.Add:16    Duration.Shift:15
// time.Add:16    Duration.Shift:15
// ...

Months are tricky. Shifting by months uses time.AddDate(), which is great. However, be aware of how differing days in the month are accommodated. Dates will 'roll over' if the month you're shifting to has fewer days. e.g. if you start on Jan 30th and repeat every "P1M", you'll get this:

Jan 30, 2006
Mar 2, 2006
Apr 2, 2006
May 2, 2006
Jun 2, 2006
Jul 2, 2006
Aug 2, 2006
Sep 2, 2006
Oct 2, 2006
Nov 2, 2006
Dec 2, 2006
Jan 2, 2007
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].