Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hongxinhope committed Apr 8, 2016
1 parent 58d7035 commit f50248e
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 2 deletions.
Binary file added Gif/RRuleSwiftExample.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Teambition

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#RRuleSwift
Swift library for working with recurrence rules of calendar dates.

![Example](Gif/RRuleSwiftExample.gif "RRuleSwiftExample")

RRuleSwift is based on [rrule.js](https://github.com/jkbrzt/rrule).

##How To Get Started
###Carthage
Specify "RRuleSwift" in your Cartfile:
```ogdl
github "teambition/RRuleSwift"
```

###Usage
##### Initialization
```swift
var recurrenceRule = RecurrenceRule(recurrenceWithFrequency: .Daily)
recurrenceRule.calendar = ...
recurrenceRule.frequency = ...
recurrenceRule.interval = ...
recurrenceRule.firstDayOfWeek = ...
recurrenceRule.startDate = ...
recurrenceRule.recurrenceEnd = ...
recurrenceRule.bysetpos = ...
recurrenceRule.byyearday = ...
recurrenceRule.bymonth = ...
recurrenceRule.byweekno = ...
recurrenceRule.bymonthday = ...
recurrenceRule.byweekday = ...
recurrenceRule.byhour = ...
recurrenceRule.byminute = ...
recurrenceRule.bysecond = ...
```

##### Rule form string
```swift
let ruleString = "RRULE:FREQ=MONTHLY;DTSTART=20160404T021000Z;COUNT=5;INTERVAL=2;WKST=MO;BYDAY=MO,TU"
let rule = RecurrenceRule.ruleWithString(ruleString)
```

##### String form rule
```swift
let ruleString = rule.toRRuleString()
print(ruleString)
// RRULE:FREQ=MONTHLY;DTSTART=20160404T021000Z;COUNT=5;INTERVAL=2;WKST=MO;BYDAY=MO,TU
```

##### Occurrence generator
```swift
let ruleString = "RRULE:FREQ=YEARLY;COUNT=5;WKST=MO"
if let rule = RecurrenceRule.ruleWithString(ruleString) {
let allDates = rule.allOccurrences()
print(allDates)
/*
2016-04-06 14:26:17 Wed,
2017-04-06 14:26:17 Thu,
2018-04-06 14:26:17 Fri,
2019-04-06 14:26:17 Sat,
2020-04-06 14:26:17 Mon
*/

let date = dateFormatter.dateFromString("2017-01-01 00:00:00 Sun")
let otherDate = dateFormatter.dateFromString("2020-01-01 00:00:00 Wed")
let betweenDates = rule.occurrencesBetween(date: date!, andDate: otherDate!)
print(betweenDates)
/*
2017-04-06 14:26:17 Thu,
2018-04-06 14:26:17 Fri,
2019-04-06 14:26:17 Sat
*/
}
```

## Minimum Requirement
iOS 8.0

## Release Notes
* [Release Notes](https://github.com/teambition/RRuleSwift/releases)

## License
RRuleSwift is released under the MIT license. See [LICENSE](https://github.com/teambition/RRuleSwift/blob/master/LICENSE.md) for details.

## More Info
Have a question? Please [open an issue](https://github.com/teambition/RRuleSwift/issues/new)!
2 changes: 1 addition & 1 deletion RRuleSwift/RecurrenceRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct RecurrenceRule {
public var calendar = NSCalendar.currentCalendar()

/// The frequency of the recurrence rule.
public var frequency: RecurrenceFrequency!
public var frequency: RecurrenceFrequency

/// Specifies how often the recurrence rule repeats over the unit of time indicated by its frequency. For example, a recurrence rule with a frequency type of RecurrenceFrequency.Weekly and an interval of 2 repeats every two weeks.
///
Expand Down
2 changes: 1 addition & 1 deletion RRuleSwiftExample/RRuleExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ extension RRuleExampleViewController: UIPickerViewDataSource, UIPickerViewDelega
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
switch pickerView.tag {
case 0:
rule.frequency = kFrequenciesDic[kFrequencies[row]]
rule.frequency = kFrequenciesDic[kFrequencies[row]]!
case 1:
rule.interval = row + 1
case 2:
Expand Down

0 comments on commit f50248e

Please sign in to comment.