GithubHelp home page GithubHelp logo

swiftdates's Introduction

Swift Dates

BSD. Use at your own risk.

Various datelike things.

Date Utilities

  • Adds sharedCalendar and now as Date static property
  • Implements date properites for time interval and component retrieval
  • Date characteristics (past, future, weekend, weekday)
  • Time interval between two dates, from one date to another, single component distance
  • Returning days/hours/minutes/seconds to another date
  • Offsets (dhms) to another date
  • Nearest hour and minute
  • Start of day, end of day, end of today, start of week, next week, last week, this week, start of year, next year, last year
  • Today, tomorrow, yesterday for real time and for a given date
  • Whether two dates are on the same day, same week, same year

Date Math

  • Common time intervals (smhdw)
  • Integer interval math (1.day, 2.weeks, etc, smhdw)
  • Date + Components
  • Components +/- Components

Date Formatting

  • ISO 8601 formatter, short/medium/long/full date and time formatters
  • ISO 8601/short/medium/long/full date strings
  • Short/medium/long/full time strings

Calendar Utilities

  • Comprehensive component(of date: Date) for all standard components, for any calendar.

Date Component Utilities

  • Common, comprehensive, MDY, HMS, MDYHMS component sets
  • Common, comprehensive, MDY, HMS, and MDYHMS component date properties
  • Populate date components by single MDYHMSn component counts
  • Offset date by count of a single component:
    • offset(_ component: Calendar.Component, _ count: Int) -> Date
  • Date component subscripting
  • Initialize date components from time interval DateComponents(ti:)
  • Return a set of members making up an individual date component instance
  • Standardization: trimmed (zero-valued components removed, normalized (all positive values), timeInteval (representation of the date components as a time interval offset from the reference date)
  • Presentation: standard, relative, approximate
let dc = DateComponents(minute: 7, second: 5)
print(dc.description(remaining: true, approximate: true)) 
// About 7 minutes, 5 seconds remaining
print(dc.description(style: .approximate)) 
// About 7 minutes from now
print(dc.description(style: .relative)) 
// 7 minutes, 5 seconds from now
print(dc.description(style: .standard)) 
// 7 minutes, 5 seconds
let units: [DateComponentsFormatter.UnitsStyle] = 
    [.positional, .abbreviated, .short, .full, .spellOut]
// 7:05, 7m 5s, 7 min, 5 sec, 7 minutes, 5 seconds, seven minutes, five seconds

swiftdates's People

Contributors

dbmrq avatar erica avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftdates's Issues

Formatter locale

I didn't make a PR already because I don't know if there's a reason for this, but wouldn't it be better if the shortDateFormatter et al. used Locale.autoupdatingCurrent?

E.g.:

public static var shortDateFormatter: DateFormatter = {
    $0.locale = Locale.autoupdatingCurrent
    $0.dateStyle = .short; return $0
}(DateFormatter())

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.