All Projects → davedelong → Time

davedelong / Time

Licence: mit
Building a better date/time library for Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Time

nepali-datetime
Python's core datetime inspired nepali datetime (BS date & NPT) package 🇳🇵
Stars: ✭ 36 (-98.18%)
Mutual labels:  time, datetime, date, calendar, timezone
Date
A date and time library based on the C++11/14/17 <chrono> header
Stars: ✭ 2,389 (+20.47%)
Mutual labels:  time, date, datetime, timezone, calendar
Laydate
layDate(日期与时间组件) 是 layui 独立维护的三大组件之一
Stars: ✭ 1,066 (-46.24%)
Mutual labels:  time, date, datetime, calendar
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (-98.18%)
Mutual labels:  time, datetime, date, date-formatting
Luatz
Time, Date and Timezone library for lua
Stars: ✭ 92 (-95.36%)
Mutual labels:  time, date, datetime, timezone
hs-hourglass
efficient and simpler time API for haskell
Stars: ✭ 43 (-97.83%)
Mutual labels:  time, datetime, date, timezone
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 (-97.02%)
Mutual labels:  time, datetime, date, calendar
Calendarview
An Easy to Use Calendar for iOS (Swift 5.0)
Stars: ✭ 429 (-78.37%)
Mutual labels:  date, datetime, date-time, calendar
React Datetime Picker
A datetime picker for your React app.
Stars: ✭ 294 (-85.17%)
Mutual labels:  time, date, datetime, calendar
Tail.datetime
A lightweight, translat- and configurable Open Source DateTime Picker, written in pure vanilla JavaScript!
Stars: ✭ 139 (-92.99%)
Mutual labels:  time, date, datetime, calendar
Period
PHP's time range API
Stars: ✭ 616 (-68.94%)
Mutual labels:  time, date, datetime, calendar
Delorean
Delorean: Time Travel Made Easy
Stars: ✭ 1,793 (-9.58%)
Mutual labels:  time, date, datetime, timezone
Dpicker
A framework-agnostic minimal date picker
Stars: ✭ 187 (-90.57%)
Mutual labels:  time, date, datetime, calendar
Dayjs
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
Stars: ✭ 37,373 (+1784.67%)
Mutual labels:  time, date, datetime, date-formatting
Angular Moment Picker
Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js.
Stars: ✭ 536 (-72.97%)
Mutual labels:  time, date, datetime, calendar
Swiftdate
🐔 Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift.
Stars: ✭ 6,661 (+235.91%)
Mutual labels:  date, timezone, date-time, date-formatting
Calendar
📅 PHP Date & Time library that solves common problems in object oriented, immutable way.
Stars: ✭ 113 (-94.3%)
Mutual labels:  time, date, datetime, calendar
Chrono
Date and time library for Rust
Stars: ✭ 1,780 (-10.24%)
Mutual labels:  time, date, calendar
When
A natural language date/time parser with pluggable rules
Stars: ✭ 1,113 (-43.87%)
Mutual labels:  time, date, datetime
Date Fns Timezone
Parsing and formatting date strings using IANA time zones for date-fns.
Stars: ✭ 118 (-94.05%)
Mutual labels:  time, date, timezone

Time

Time is a Swift package that makes dealing with calendar values a natural and straight-forward process.

Working with calendars can be extremely complicated and error-prone. Time solves these problems by clarifying concepts and restricting improper usage through type-safe APIs.

Installing

Time can be installed like any other Swift package. Add this to the dependencies section of your Package.swift:

.package(url: "https://github.com/davedelong/time", from: "0.9.1")

The Basics

Here's the TL;DR of the documentation:

  • If you want to know what time it is, you need a Clock. You can get the device's clock by using Clocks.system.

  • A Clock can tell you the current time via some functions. For example, .today() will give you the current calendar day. .thisMinute() will give you the current time, accurate down to the minute level.

  • Each of these returned values has methods to retrieve more- and less- precise values. For example, today.hours() will give you a sequence of all the "Hour" values in the day.

  • These values also are how you format them into human-readable strings (via the .format(...) method)

Some Small Examples

There are some examples below showing a sneak peek of what you can do with Time.

Fetching the Current Time

let clock = Clocks.system

// retrieve the current instantaneous time from the clock
let now = clock.thisInstant()

// retrieve the current calendar day, as defined by the user's region
let today = clock.today()

More information in "Clock".

Converting Between Regions

let nycTimeZone = TimeZone(identifier: "America/New_York")!

let myClock = Clocks.system
let nycClock = myClock.converting(to: nycTimeZone)

let myLocalTime = myClock.thisMinute() // Ex: 28 Feb 2020 at 3:14 PM Pacific Time

let nycLocalTime = nycClock.thisMinute() // Ex: 28 Feb 2020 at 6:14 PM Eastern Time

More information in "Clock".

Retrieving Components

let today: Absolute<Day> = myClock.today()
let year = today.year // Ex: 2020
let month = today.month // Ex: 2
let day = today.day // Ex: 28

More information in "TimePeriod".

Calculating Differences

let day1: Absolute<Day> = ...
let day2: Absolute<Day> = ...

// compute the difference in days, months, years, and eras
let difference: TimeDifference<Day, Era> = day1.difference(to: day2)

// or conveniently the number of calendar days between the two values
let daysDifference = day1.differenceInDays(to: day2)

More information in "Differences".

Iterating Over TimePeriods

let thisMonth = Clocks.system.thisMonth()
let daysInThisMonth = thisMonth.days()

for day in daysInThisMonth {
    //
}

More information in "Iterating Over TimePeriods".

Formatting TimePeriods

let today: Absolute<Day> = ...

let fullYearString = today.format(date: .full) // Ex: February 28, 2020
let shortYearString = today.format(year: .twoDigits, month: .full) // Ex: February '20

More information in "Formatting TimePeriods".

Observing time changes

let clock: Clock = ...
clock
    .chime(every: .seconds(5))
    .sink { (value: Absolute<Second>) in
        print("Another 5 seconds have passed")
    }
    .store(in: &cancellables)

More information in "Observing time changes".

Detailed Information

For more information, please see the documentation.

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].