All Projects → kawoou → Anydate

kawoou / Anydate

Licence: mit
Swifty Date & Time API inspired from Java 8 DateTime API.

Programming Languages

java
68154 projects - #9 most used programming language
swift
15916 projects

Projects that are alternatives of or similar to Anydate

Datez
📆 Breeze through Date, DateComponents, and TimeInterval with Swift!
Stars: ✭ 254 (+42.7%)
Mutual labels:  datetime, tvos, watchos
Delorean
Delorean: Time Travel Made Easy
Stars: ✭ 1,793 (+907.3%)
Mutual labels:  datetime, timezone
Ducttape
📦 KeyPath dynamicMemberLookup based syntax sugar for Swift.
Stars: ✭ 138 (-22.47%)
Mutual labels:  tvos, watchos
Mirrordiffkit
Graduation from messy XCTAssertEqual messages.
Stars: ✭ 168 (-5.62%)
Mutual labels:  tvos, watchos
Xamarin Macios
Bridges the worlds of .NET with the native APIs of macOS, iOS, tvOS, and watchOS.
Stars: ✭ 2,109 (+1084.83%)
Mutual labels:  tvos, watchos
Opencombine
Open source implementation of Apple's Combine framework for processing values over time.
Stars: ✭ 2,040 (+1046.07%)
Mutual labels:  tvos, watchos
Cdmarkdownkit
An extensive Swift framework providing simple and customizable markdown parsing.
Stars: ✭ 158 (-11.24%)
Mutual labels:  tvos, watchos
Cloudkitgdpr
Framework for allowing users to manage data stored in iCloud
Stars: ✭ 126 (-29.21%)
Mutual labels:  tvos, watchos
Noticeobservekit
NoticeObserveKit is type-safe NotificationCenter wrapper.
Stars: ✭ 147 (-17.42%)
Mutual labels:  tvos, watchos
Berkanansdk
Bluetooth mesh messaging SDK for apps
Stars: ✭ 150 (-15.73%)
Mutual labels:  tvos, watchos
Mapboxstatic.swift
Static map snapshots with overlays in Swift or Objective-C on iOS, macOS, tvOS, and watchOS
Stars: ✭ 162 (-8.99%)
Mutual labels:  tvos, watchos
Swiftui Shapes
🚀 Collection of SwiftUI shapes
Stars: ✭ 137 (-23.03%)
Mutual labels:  tvos, watchos
Alley
Essential `URLSessionDataTask` micro-wrapper for communication with HTTP(S) web services, with built-in automatic request retries.
Stars: ✭ 137 (-23.03%)
Mutual labels:  tvos, watchos
Swifthttpstatuscodes
Swift enum wrapper for easier handling of HTTP status codes.
Stars: ✭ 159 (-10.67%)
Mutual labels:  tvos, watchos
Contentful.swift
A delightful Swift interface to Contentful's content delivery API.
Stars: ✭ 132 (-25.84%)
Mutual labels:  tvos, watchos
Cocoalumberjack
A fast & simple, yet powerful & flexible logging framework for Mac and iOS
Stars: ✭ 12,584 (+6969.66%)
Mutual labels:  tvos, watchos
Time
Building a better date/time library for Swift
Stars: ✭ 1,983 (+1014.04%)
Mutual labels:  datetime, timezone
Persistencekit
Store and retrieve Codable objects to various persistence layers, in a couple lines of code!
Stars: ✭ 121 (-32.02%)
Mutual labels:  tvos, watchos
Iconic
🎨 Auto-generated icon font library for iOS, watchOS and tvOS
Stars: ✭ 1,567 (+780.34%)
Mutual labels:  tvos, watchos
Color
Color utilities for macOS, iOS, tvOS, and watchOS
Stars: ✭ 145 (-18.54%)
Mutual labels:  tvos, watchos

AnyDate

Awesome Swift Carthage compatible Version License CI Status Codecov Platform Jazzy

Swifty Date & Time API inspired from Java 8 DateTime API.

Background

I think that date & time API should be easy and accurate.

Previous dates, times, timezones API of Swift are inconvenience to use. (It's very complex to create, manipulate or everything else.)

But there's quite nice pioneer, The Brand New Time API of Java8.

Java 8 introduced whole new API for handle date & time more efficiently and easy a.k.a LocalDateTime, ZonedDateTime(JSR-310). The main idea that is:

  • Immutable-value classes
  • Domain-driven design
  • Separation of chronologies

Those ideas can be easily ported to another languages, like .Net's Rx ports of another languages.

So, here's the AnyDate, whole new Swift date & time API that has coherence between Java 8.

Features

  • [x] Convinience typed year, month, day, time.
  • [x] Pre-defined Timezone Identifiers.
  • [x] Null-Safe types.
  • [x] Separation of chronologies.
  • [x] Coherence with Java.
  • [x] Operators supported.
  • [x] Easy to manipulate.

FAQ

  • Looks like SwiftDate?
    • SwiftDate is a support library for Date, AnyDate can completely replace Date.

Usage

  • Convinience typed year, month, day, time.
/// Before
let now1 = Date()
var calendar = Calendar.current
calendar.timeZone = TimeZone(identifier: "UTC")!

let day = calendar.components(.day, from: now1)

/// After
let now2 = ZonedDateTime(Clock.utc)
let day = now2.day
  • Pre-defined Timezone Identifiers. String typed timezones are not safe from your TYPING ERROR. (Plz, do not belive your finger. They can always betray you.)
/// Before
let timeZone1 = TimeZone(identifier: "GMT+0900")!
let timeZone2 = TimeZone(identifier: "America/Argentina/Buenos_Aires")!

/// After
let clock1 = Clock(offsetHour: 9)
let clock2 = Clock(identifier: .americaArgentinaBuenosAires)
  • Null-Safe types. NO MORE NEEDLESS GUARD & OPTIONAL AND INDENT INCRESEMENT :-D
/// Before
var dateComponents = DateComponents()
dateComponents.year = 2000
dateComponents.month = 11
dateComponents.day = 30
dateComponents.hour = 11
dateComponents.minute = 51
dateComponents.second = 18
dateComponents.nanosecond = 1573

guard let date = Calendar.current.date(from: dateComponents) else {
    assertionFailure("Failed to create!")
    return
}

/// After
let date = LocalDateTime(
    year: 2000,
    month: 11,
    day: 30,
    hour: 11,
    minute: 51,
    second: 18,
    nanoOfSecond: 1573
)
  • Operators supported. Easy to compare dates, datetimes, times.
let min = ZonedDateTime.min
let max = ZonedDateTime.max

let oldDate = ZonedDateTime(year: 1627, month: 2, day: 10, hour: 14, minute: 2, second: 18, nanoOfSecond: 1573, clock: .UTC)
let newDate = ZonedDateTime(year: 1627, month: 2, day: 10, hour: 14, minute: 2, second: 18, nanoOfSecond: 1574, clock: .UTC)
let equalDate = ZonedDateTime(year: 1627, month: 2, day: 10, hour: 14, minute: 2, second: 18, nanoOfSecond: 1573, clock: .UTC)

let isLessThan = min < oldDate
let isGreaterThan = max > newDate
let isLessThanOrEqual = oldDate <= equalDate
let isGreaterThanOrEqual = oldDate >= equalDate
let isEqual = oldDate == equalDate
let isLessThan = oldDate < newDate
  • Easy to manipulate. You can use our overridden operators to create / add / sub dates and times.
/// 1000-01-07T11:51:18.000001573
let date = LocalDateTime(
    year: 1000,
    month: 1,
    day: 7,
    hour: 11,
    minute: 51,
    second: 18,
    nanoOfSecond: 1573
)
print(date)

/// Period(year: 1, month: 1, day: 9, hour: 2, minute: 3, second: 4, nano: 152)
let period = 1.year + 1.month + 1.week + 2.day + 2.hour + 3.minute + 4.second + 152.nanosecond

/// 1001-03-16T13:54:22.000001725
let newDate = date + period
print(newDate)

Installation

CocoaPods:

pod 'AnyDate', '~> 1.2.0'

Carthage:

github "kawoou/AnyDate" ~> 1.2.0

Swift Package Manager:

import PackageDescription

let package = Package(
  name: "MyAwesomeApp",
  dependencies: [
    .Package(url: "https://github.com/kawoou/AnyDate", majorVersion: 1),
  ]
)

Manually

You can either simply drag and drop the Sources folder into your existing project.

Requirements

  • Swift 3.1
  • iOS 8.0+
  • tvOS 9.0+
  • macOS 10.10+
  • watchOS 2.0+
  • Virtually any platform which is compatible with Swift 3 and implements the Swift Foundation Library.

Changelog

  • 1.0.0 - 2017/08/13
    • First release AnyDate!
  • 1.0.1 - 2017/08/16
    • Increase test codes.
    • Implement CustomPlaygroundQuickLookable, CustomReflectable protocols.
  • 1.0.2 - 2017/08/26
    • Increase test codes.
    • Support Codable protocol in swift 4.
    • Add operators on Instant.
  • 1.0.3 - 2017/09/03
    • Hotfix, Comparable bugs.
  • 1.0.4 - 2017/10/07
    • Fix Calendar(identifier: .iso8601) crash on swift SR-3828.
  • 1.0.5 - 2018/04/11
    • Support for Swift 4.1 and Xcode 9.3.
  • 1.0.6 - 2018/05/20
    • Support Hashable.
  • 1.1.0 - 2018/10/18
    • Support for Swift 4.2.
  • 1.2.0 - 2019/04/04
    • Support for Swift 5.0.

Author

Special Thanks

  • Naming by 아메바

License

AnyDate is under MIT license. See the LICENSE file for more info.

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