Skip to content

Commit

Permalink
Merge pull request #10 from mobillium/feature/prepare-1.2.0
Browse files Browse the repository at this point in the history
prepare version 1.2.0
  • Loading branch information
aslanmehmetsalih authored Mar 19, 2021
2 parents 8cc75cb + 2dca984 commit 07c392b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Example/MobilliumDateFormatter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand Down Expand Up @@ -333,6 +334,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- MobilliumDateFormatter (1.1.0)
- MobilliumDateFormatter (1.2.0)

DEPENDENCIES:
- MobilliumDateFormatter (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
MobilliumDateFormatter: eccff23e7c493446d1600b123afc7a2da0e7b3cb
MobilliumDateFormatter: 398a47e62aeeda24385c362c61c213550b07f047

PODFILE CHECKSUM: 873107ad216c46c49665232acadad65fc6e21ea1

Expand Down
2 changes: 1 addition & 1 deletion Example/Tests/MathOperationsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MathOperationsTests: XCTestCase {
let date2 = Date(timeIntervalSince1970: 1614778576) // 2021-03-03 13:36:16

// Create result Date
let resultDate = date.add(.milisecond, count: 5000)
let resultDate = date.add(.millisecond, count: 5000)

// Check
XCTAssertEqual(date2, resultDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public extension Date {
case hour
case minute
case second
case milisecond
case millisecond
}

}
5 changes: 4 additions & 1 deletion MobilliumDateFormatter/Classes/Date+DateFormater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ public extension Date {

/// Creates a Date using 'TimeInterval'
static func from(_ timeInterval: TimeInterval) -> Date? {
return Date(timeIntervalSince1970: timeInterval)
let date = Date(timeIntervalSince1970: timeInterval)
return date
}

/// Creates a Date using 'dateString' and 'Date.Format'.
static func from(_ dateString: String, format: Date.Format) -> Date? {
let dateformatter = DateFormatter()
dateformatter.calendar = MobilliumDateFormatter.calendar
dateformatter.locale = MobilliumDateFormatter.locale
dateformatter.dateFormat = format.rawValue
return dateformatter.date(from: dateString)
Expand All @@ -23,6 +25,7 @@ public extension Date {
/// Creates a String using 'Date'.
func to(_ format: Date.Format) -> String {
let dateformatter: DateFormatter = DateFormatter()
dateformatter.calendar = MobilliumDateFormatter.calendar
dateformatter.locale = MobilliumDateFormatter.locale
dateformatter.dateFormat = format.rawValue
return dateformatter.string(from: self)
Expand Down
3 changes: 1 addition & 2 deletions MobilliumDateFormatter/Classes/Date+MathOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public extension Date {

func add(_ component: DateComponentType, count: Int) -> Date? {
switch component {
case .milisecond:
case .millisecond:
return addMillisecond(count)
case .second:
return addSecond(count)
Expand Down Expand Up @@ -69,5 +69,4 @@ public extension Date {
return calendar.date(byAdding: .year, value: count, to: self)
}


}
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MobilliumDateFormatter

[![CI Status](https://img.shields.io/travis/aslanmehmetsalih/MobilliumDateFormatter.svg?style=flat)](https://travis-ci.org/mobillium/MobilliumDateFormatter)
[![Build Status](https://github.com/mobillium/MobilliumDateFormatter/workflows/CI/badge.svg?branch=master)](https://github.com/mobillium/MobilliumDateFormatter/actions)
[![Version](https://img.shields.io/cocoapods/v/MobilliumDateFormatter.svg?style=flat)](https://cocoapods.org/pods/MobilliumDateFormatter)
[![License](https://img.shields.io/cocoapods/l/MobilliumDateFormatter.svg?style=flat)](https://cocoapods.org/pods/MobilliumDateFormatter)
[![Platform](https://img.shields.io/cocoapods/p/MobilliumDateFormatter.svg?style=flat)](https://cocoapods.org/pods/MobilliumDateFormatter)
Expand All @@ -11,7 +11,8 @@ To run the example project, clone the repo, and run `pod install` from the Examp

## Requirements

- iOS 8.0+
- iOS 9.0+
- Swift 5.0+

## Installation

Expand Down Expand Up @@ -141,6 +142,11 @@ Set locale(optional):
MobilliumDateFormatter.locale = Locale(identifier: "us")
```

Set calendar(optional), default: Calendar.current:
```swift
MobilliumDateFormatter.calendar = Calendar.current
```

String to Date:
```swift
let dateString = "2001-01-01 01:01:00"
Expand All @@ -159,6 +165,28 @@ let timeInterval = TimeInterval(exactly: 1549611277)!
let date = Date.from(timeInterval)
```

supported date component types for math operations:
```swift
enum DateComponentType {
case year
case month
case weekOfYear
case day
case hour
case minute
case second
case millisecond
}
```

example of adding days(you can add another date component type like this):
```swift
let date = Date()
let newDate = date.add(.day, count: 1)
// or
let newDate = now.addDay(-1)
```

## License

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

0 comments on commit 07c392b

Please sign in to comment.