├── .gitignore ├── Screenshots ├── iOS.png ├── macOS.png └── tvOS.png ├── Sample Apps └── ChronoSample │ ├── Chrono tvOS │ ├── Assets.xcassets │ │ ├── Contents.json │ │ ├── App Icon & Top Shelf Image.brandassets │ │ │ ├── App Icon - Large.imagestack │ │ │ │ ├── Back.imagestacklayer │ │ │ │ │ ├── Contents.json │ │ │ │ │ └── Content.imageset │ │ │ │ │ │ └── Contents.json │ │ │ │ ├── Front.imagestacklayer │ │ │ │ │ ├── Contents.json │ │ │ │ │ └── Content.imageset │ │ │ │ │ │ └── Contents.json │ │ │ │ ├── Middle.imagestacklayer │ │ │ │ │ ├── Contents.json │ │ │ │ │ └── Content.imageset │ │ │ │ │ │ └── Contents.json │ │ │ │ └── Contents.json │ │ │ ├── App Icon - Small.imagestack │ │ │ │ ├── Back.imagestacklayer │ │ │ │ │ ├── Contents.json │ │ │ │ │ └── Content.imageset │ │ │ │ │ │ └── Contents.json │ │ │ │ ├── Front.imagestacklayer │ │ │ │ │ ├── Contents.json │ │ │ │ │ └── Content.imageset │ │ │ │ │ │ └── Contents.json │ │ │ │ ├── Middle.imagestacklayer │ │ │ │ │ ├── Contents.json │ │ │ │ │ └── Content.imageset │ │ │ │ │ │ └── Contents.json │ │ │ │ └── Contents.json │ │ │ ├── Top Shelf Image.imageset │ │ │ │ └── Contents.json │ │ │ ├── Top Shelf Image Wide.imageset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ └── LaunchImage.launchimage │ │ │ └── Contents.json │ ├── Info.plist │ ├── ViewController.swift │ ├── AppDelegate.swift │ └── Base.lproj │ │ └── Main.storyboard │ ├── ChronoSample.xcodeproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcuserdata │ │ │ └── Neil.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── xcuserdata │ │ └── Neil.xcuserdatad │ │ │ └── xcschemes │ │ │ ├── xcschememanagement.plist │ │ │ ├── Chrono iOS.xcscheme │ │ │ ├── Chrono tvOS.xcscheme │ │ │ └── Chrono macOS.xcscheme │ └── project.pbxproj │ ├── Chrono macOS │ ├── AppDelegate.swift │ ├── Info.plist │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── ViewController.swift │ └── Base.lproj │ │ └── Main.storyboard │ ├── Chrono iOS │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── ViewController.swift │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ └── AppDelegate.swift │ └── Chrono │ ├── LICENSE.txt │ ├── ChronoParsedResult.swift │ └── Chrono.swift ├── LICENSE ├── README.md └── Chrono ├── ChronoParsedResult.swift └── Chrono.swift /.gitignore: -------------------------------------------------------------------------------- 1 | **/.DS_Store 2 | *.xcuserstate 3 | 4 | -------------------------------------------------------------------------------- /Screenshots/iOS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neilsardesai/chrono-swift/HEAD/Screenshots/iOS.png -------------------------------------------------------------------------------- /Screenshots/macOS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neilsardesai/chrono-swift/HEAD/Screenshots/macOS.png -------------------------------------------------------------------------------- /Screenshots/tvOS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neilsardesai/chrono-swift/HEAD/Screenshots/tvOS.png -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/ChronoSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/ChronoSample.xcodeproj/project.xcworkspace/xcuserdata/Neil.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neilsardesai/chrono-swift/HEAD/Sample Apps/ChronoSample/ChronoSample.xcodeproj/project.xcworkspace/xcuserdata/Neil.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image Wide.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/ChronoSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "landscape", 5 | "idiom" : "tv", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "9.0", 8 | "scale" : "1x" 9 | } 10 | ], 11 | "info" : { 12 | "version" : 1, 13 | "author" : "xcode" 14 | } 15 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "layers" : [ 3 | { 4 | "filename" : "Front.imagestacklayer" 5 | }, 6 | { 7 | "filename" : "Middle.imagestacklayer" 8 | }, 9 | { 10 | "filename" : "Back.imagestacklayer" 11 | } 12 | ], 13 | "info" : { 14 | "version" : 1, 15 | "author" : "xcode" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "layers" : [ 3 | { 4 | "filename" : "Front.imagestacklayer" 5 | }, 6 | { 7 | "filename" : "Middle.imagestacklayer" 8 | }, 9 | { 10 | "filename" : "Back.imagestacklayer" 11 | } 12 | ], 13 | "info" : { 14 | "version" : 1, 15 | "author" : "xcode" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono macOS/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Chrono macOS 4 | // 5 | // Created by Neil Sardesai on 2016-11-17. 6 | // Copyright © 2016 Neil Sardesai. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | @NSApplicationMain 12 | class AppDelegate: NSObject, NSApplicationDelegate { 13 | 14 | 15 | 16 | func applicationDidFinishLaunching(_ aNotification: Notification) { 17 | // Insert code here to initialize your application 18 | } 19 | 20 | func applicationWillTerminate(_ aNotification: Notification) { 21 | // Insert code here to tear down your application 22 | } 23 | 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono iOS/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "assets" : [ 3 | { 4 | "size" : "1280x768", 5 | "idiom" : "tv", 6 | "filename" : "App Icon - Large.imagestack", 7 | "role" : "primary-app-icon" 8 | }, 9 | { 10 | "size" : "400x240", 11 | "idiom" : "tv", 12 | "filename" : "App Icon - Small.imagestack", 13 | "role" : "primary-app-icon" 14 | }, 15 | { 16 | "size" : "2320x720", 17 | "idiom" : "tv", 18 | "filename" : "Top Shelf Image Wide.imageset", 19 | "role" : "top-shelf-image-wide" 20 | }, 21 | { 22 | "size" : "1920x720", 23 | "idiom" : "tv", 24 | "filename" : "Top Shelf Image.imageset", 25 | "role" : "top-shelf-image" 26 | } 27 | ], 28 | "info" : { 29 | "version" : 1, 30 | "author" : "xcode" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIMainStoryboardFile 24 | Main 25 | UIRequiredDeviceCapabilities 26 | 27 | arm64 28 | 29 | UIUserInterfaceStyle 30 | Automatic 31 | 32 | 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright © 2016 Neil Sardesai 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the “Software”), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2014, Wanasit Tanakitrungruang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono macOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | Copyright © 2016 Neil Sardesai. All rights reserved. 27 | NSMainStoryboardFile 28 | Main 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono macOS/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/ChronoSample.xcodeproj/xcuserdata/Neil.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Chrono iOS.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | Chrono macOS.xcscheme 13 | 14 | orderHint 15 | 2 16 | 17 | Chrono tvOS.xcscheme 18 | 19 | orderHint 20 | 1 21 | 22 | 23 | SuppressBuildableAutocreation 24 | 25 | 28E5C1EC1DDE54770056DFB2 26 | 27 | primary 28 | 29 | 30 | 28E5C23C1DDE6B540056DFB2 31 | 32 | primary 33 | 34 | 35 | 28E5C2531DDE6F1E0056DFB2 36 | 37 | primary 38 | 39 | 40 | 28E5C2831DDE73A30056DFB2 41 | 42 | primary 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono iOS/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Chrono iOS 4 | // 5 | // Created by Neil Sardesai on 2016-11-17. 6 | // Copyright © 2016 Neil Sardesai. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | // MARK: IBOutlets 14 | 15 | @IBOutlet weak var discoveredDateLabel: UILabel! 16 | @IBOutlet weak var inputField: UITextField! 17 | 18 | // MARK: Lifecycle 19 | 20 | override func viewDidLoad() { 21 | super.viewDidLoad() 22 | discoveredDateLabel.text = "" 23 | inputField.addTarget(self, action: #selector(updateDiscoveredDateLabel), for: .editingChanged) 24 | } 25 | 26 | @objc func updateDiscoveredDateLabel() { 27 | let chrono = Chrono.shared 28 | let date = chrono.dateFrom(naturalLanguageString: inputField.text!) 29 | 30 | // Make the date pretty 31 | let dateFormatter = DateFormatter() 32 | dateFormatter.dateStyle = .long 33 | dateFormatter.timeStyle = .long 34 | 35 | guard let discoveredDate = date else { 36 | discoveredDateLabel.text = "" 37 | return 38 | } 39 | 40 | discoveredDateLabel.text = dateFormatter.string(from: discoveredDate) 41 | } 42 | 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Chrono tvOS 4 | // 5 | // Created by Neil Sardesai on 2016-11-17. 6 | // Copyright © 2016 Neil Sardesai. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | // MARK: IBOutlets 14 | 15 | @IBOutlet weak var discoveredDateLabel: UILabel! 16 | @IBOutlet weak var inputField: UITextField! 17 | 18 | // MARK: Lifecycle 19 | 20 | override func viewDidLoad() { 21 | super.viewDidLoad() 22 | discoveredDateLabel.text = "" 23 | inputField.addTarget(self, action: #selector(updateDiscoveredDateLabel), for: .editingChanged) 24 | } 25 | 26 | @objc func updateDiscoveredDateLabel() { 27 | let chrono = Chrono.shared 28 | let date = chrono.dateFrom(naturalLanguageString: inputField.text!) 29 | 30 | // Make the date pretty 31 | let dateFormatter = DateFormatter() 32 | dateFormatter.dateStyle = .long 33 | dateFormatter.timeStyle = .long 34 | 35 | guard let discoveredDate = date else { 36 | discoveredDateLabel.text = "" 37 | return 38 | } 39 | 40 | discoveredDateLabel.text = dateFormatter.string(from: discoveredDate) 41 | } 42 | 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono macOS/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Chrono macOS 4 | // 5 | // Created by Neil Sardesai on 2016-11-17. 6 | // Copyright © 2016 Neil Sardesai. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class ViewController: NSViewController { 12 | 13 | // MARK: IBOutlets 14 | 15 | @IBOutlet weak var discoveredDateLabel: NSTextField! 16 | @IBOutlet weak var inputField: NSTextField! 17 | 18 | // MARK: Lifecycle 19 | 20 | override func viewDidLoad() { 21 | super.viewDidLoad() 22 | discoveredDateLabel.stringValue = "" 23 | inputField.delegate = self 24 | } 25 | 26 | func updateDiscoveredDateLabel() { 27 | let chrono = Chrono.shared 28 | let date = chrono.dateFrom(naturalLanguageString: inputField.stringValue) 29 | 30 | // Make the date pretty 31 | let dateFormatter = DateFormatter() 32 | dateFormatter.dateStyle = .long 33 | dateFormatter.timeStyle = .long 34 | 35 | guard let discoveredDate = date else { 36 | discoveredDateLabel.stringValue = "" 37 | return 38 | } 39 | 40 | discoveredDateLabel.stringValue = dateFormatter.string(from: discoveredDate) 41 | } 42 | 43 | 44 | } 45 | 46 | extension ViewController: NSTextFieldDelegate { 47 | 48 | func controlTextDidChange(_ obj: Notification) { 49 | updateDiscoveredDateLabel() 50 | } 51 | 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono iOS/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Chrono tvOS 4 | // 5 | // Created by Neil Sardesai on 2016-11-17. 6 | // Copyright © 2016 Neil Sardesai. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono iOS/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Chrono iOS 4 | // 5 | // Created by Neil Sardesai on 2016-11-17. 6 | // Copyright © 2016 Neil Sardesai. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # chrono-swift 2 | 3 | chrono-swift is a Swift wrapper for [Wanasit Tanakitrungruang’s excellent chrono.js natural language date parser](https://github.com/wanasit/chrono "chrono.js"). chrono-swift lets you use chrono.js for your iOS, macOS, or tvOS apps, all while working with native Swift and Foundation data types. No need to deal with any of JavaScript’s silliness. 4 | 5 | chrono-swift, (referred to as “Chrono” from here onwards), extracts date information from natural language phrases like **“Remind me in 2 days”** or **“Meet me this Saturday from 3-4 PM”** and returns Swift `Date` or `DateInterval` values. 6 | 7 | # Setup 8 | 9 | Just add the “Chrono” folder located at the root of the repo to your Xcode project. 10 | 11 | # Usage 12 | 13 | Using Chrono is easy. First, create an instance of the `Chrono` singleton: 14 | 15 | ```swift 16 | let chrono = Chrono.shared 17 | ``` 18 | 19 | ### Extract Date 20 | 21 | To extract a date from a natural language phrase, simply pass in the phrase to `Chrono`’s `dateFrom(naturalLanguageString:)` method. Here, the reference date is assumed to be the current system date. 22 | 23 | ```swift 24 | let date = chrono.dateFrom(naturalLanguageString: "Remind me in 2 days") 25 | // If today is November 17th, 2016, `date` will be November 19th, 2016 26 | ``` 27 | 28 | If you want to use a different date as the reference date, use `dateFrom(naturalLanguageString:referenceDate:)` 29 | 30 | ### Extract Date Interval 31 | 32 | To extract a date interval from a natural language phrase, pass in the phrase to `Chrono`’s `dateIntervalFrom(naturalLanguageString:)` method. Again, the reference date is assumed to be the current system date here. 33 | 34 | ```swift 35 | let dateInterval = chrono.dateIntervalFrom(naturalLanguageString: "Meet me this Saturday from 3-4 PM") 36 | // If today is November 17th, 2016, `dateInterval` will be November 19th, 2016 3:00 PM - November 19th, 2016 4:00 PM 37 | ``` 38 | 39 | If you want to use a different date as the reference date, use `dateIntervalFrom(naturalLanguageString:referenceDate:)` 40 | 41 | ### Detailed Parsed Results 42 | 43 | You can also get more detailed parsed results using `Chrono`’s `parsedResultsFrom(naturalLanguageString:)` method. 44 | 45 | ```swift 46 | let result = chrono.parsedResultsFrom(naturalLanguageString: "I have an appointment tomorrow from 10 to 11 AM", referenceDate: nil) // If referenceDate is nil, it is assumed to be the current system date. 47 | print(results) 48 | ``` 49 | 50 | `result` will be a special struct of type `ChronoParsedResult`. This struct contains several member variables that describe the parsed result. In this case, the struct will look like this: 51 | 52 | ``` 53 | inputString: I have an appointment tomorrow from 10 to 11 AM 54 | indexOfStartingCharacterOfTimePhrase: 22 55 | timePhrase: tomorrow from 10 to 11 AM 56 | ignoredText: I have an appointment 57 | referenceDate: November 17, 2016 at 8:18:14 PM CST 58 | startDate: November 18, 2016 at 10:00:00 AM CST 59 | endDate: November 18, 2016 at 11:00:00 AM CST 60 | dateInterval: November 18, 2016, 10:00:00 AM CST - 11:00:00 AM CST 61 | ``` 62 | 63 | # Sample Project 64 | 65 | Under the “Sample Apps” folder is a sample Xcode project with iOS, macOS, and tvOS targets. 66 | 67 | ![Chrono iOS](Screenshots/iOS.png "Chrono iOS") 68 | 69 | ![Chrono macOS](Screenshots/macOS.png "Chrono macOS") 70 | 71 | ![Chrono tvOS](Screenshots/tvOS.png "Chrono tvOS") 72 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/ChronoSample.xcodeproj/xcuserdata/Neil.xcuserdatad/xcschemes/Chrono iOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/ChronoSample.xcodeproj/xcuserdata/Neil.xcuserdatad/xcschemes/Chrono tvOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/ChronoSample.xcodeproj/xcuserdata/Neil.xcuserdatad/xcschemes/Chrono macOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Chrono/ChronoParsedResult.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChronoParsedResult.swift 3 | // chrono-swift 4 | // 5 | // Created by Neil Sardesai on 2016-11-16. 6 | // Copyright © 2016 Neil Sardesai. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /// A struct that contains details about a parsed result from a call to `Chrono`’s `parsedResultsFrom(naturalLanguageString:referenceDate:)` method. You should not create instances of `ChronoParsedResult` yourself. 12 | struct ChronoParsedResult { 13 | 14 | /// The input natural language phrase 15 | private(set) var inputString: String? 16 | /// If the input natural language phrase were converted to an `Array` of `Character`s, this would be the index of the first `Character` of the discovered time phrase 17 | private(set) var indexOfStartingCharacterOfTimePhrase: Int? 18 | /// The discovered time phrase in the input natural language phrase 19 | private(set) var timePhrase: String? 20 | /// Text that was not part of the time phrase and was ignored 21 | private(set) var ignoredText: String? 22 | /// The reference date used for calculating `startDate` 23 | private(set) var referenceDate: Date? 24 | /// The date discovered in the input natural language phrase. If the time phrase in the natural language phrase describes an interval between two `Date`s, this is the start date of that interval 25 | private(set) var startDate: Date? 26 | /// If the time phrase in the input natural language phrase describes an interval between two `Date`s, this is the end date of that interval 27 | private(set) var endDate: Date? 28 | /// If the time phrase in the input natural language phrase describes an interval between two `Date`s, this is that `DateInterval` 29 | private(set) var dateInterval: DateInterval? 30 | 31 | init(inputString: String?, indexOfStartingCharacterOfTimePhrase: Int?, timePhrase: String?, ignoredText: String?, referenceDate: Date?, startDate: Date?, endDate: Date?, dateInterval: DateInterval?) { 32 | self.inputString = inputString 33 | self.indexOfStartingCharacterOfTimePhrase = indexOfStartingCharacterOfTimePhrase 34 | self.timePhrase = timePhrase 35 | self.ignoredText = ignoredText 36 | self.referenceDate = referenceDate 37 | self.startDate = startDate 38 | self.endDate = endDate 39 | self.dateInterval = dateInterval 40 | } 41 | 42 | 43 | } 44 | 45 | // Overriding output of `print(ChronoParsedResult)` to make it more useful 46 | extension ChronoParsedResult: CustomStringConvertible { 47 | 48 | var description: String { 49 | let inputStringDescription = self.inputString?.description ?? "nil" 50 | let indexOfStartingCharacterOfTimePhraseDescription = self.indexOfStartingCharacterOfTimePhrase?.description ?? "nil" 51 | let timePhraseDescription = self.timePhrase?.description ?? "nil" 52 | let ignoredTextDescription = self.ignoredText?.description ?? "nil" 53 | 54 | // Make the dates pretty 55 | let locale = Locale(identifier: "en_US") 56 | let dateFormatter = DateFormatter() 57 | dateFormatter.dateStyle = .long 58 | dateFormatter.timeStyle = .long 59 | dateFormatter.locale = locale 60 | 61 | var referenceDateDescription = "nil" 62 | if let referenceDate = self.referenceDate { 63 | referenceDateDescription = dateFormatter.string(from: referenceDate) 64 | } 65 | 66 | var startDateDescription = "nil" 67 | if let startDate = self.startDate { 68 | startDateDescription = dateFormatter.string(from: startDate) 69 | } 70 | 71 | var endDateDescription = "nil" 72 | if let endDate = self.endDate { 73 | endDateDescription = dateFormatter.string(from: endDate) 74 | } 75 | 76 | var dateIntervalDescription = "nil" 77 | if let dateInterval = self.dateInterval { 78 | let dateIntervalFormatter = DateIntervalFormatter() 79 | dateIntervalFormatter.dateStyle = .long 80 | dateIntervalFormatter.timeStyle = .long 81 | dateIntervalDescription = dateIntervalFormatter.string(from: dateInterval)! 82 | } 83 | 84 | return "inputString: \(inputStringDescription)\nindexOfStartingCharacterOfTimePhrase: \(indexOfStartingCharacterOfTimePhraseDescription)\ntimePhrase: \(timePhraseDescription)\nignoredText: \(ignoredTextDescription)\nreferenceDate: \(referenceDateDescription)\nstartDate: \(startDateDescription)\nendDate: \(endDateDescription)\ndateInterval: \(dateIntervalDescription)" 85 | } 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono/ChronoParsedResult.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChronoParsedResult.swift 3 | // chrono-swift 4 | // 5 | // Created by Neil Sardesai on 2016-11-16. 6 | // Copyright © 2016 Neil Sardesai. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /// A struct that contains details about a parsed result from a call to `Chrono`’s `parsedResultsFrom(naturalLanguageString:referenceDate:)` method. You should not create instances of `ChronoParsedResult` yourself. 12 | struct ChronoParsedResult { 13 | 14 | /// The input natural language phrase 15 | private(set) var inputString: String? 16 | /// If the input natural language phrase were converted to an `Array` of `Character`s, this would be the index of the first `Character` of the discovered time phrase 17 | private(set) var indexOfStartingCharacterOfTimePhrase: Int? 18 | /// The discovered time phrase in the input natural language phrase 19 | private(set) var timePhrase: String? 20 | /// Text that was not part of the time phrase and was ignored 21 | private(set) var ignoredText: String? 22 | /// The reference date used for calculating `startDate` 23 | private(set) var referenceDate: Date? 24 | /// The date discovered in the input natural language phrase. If the time phrase in the natural language phrase describes an interval between two `Date`s, this is the start date of that interval 25 | private(set) var startDate: Date? 26 | /// If the time phrase in the input natural language phrase describes an interval between two `Date`s, this is the end date of that interval 27 | private(set) var endDate: Date? 28 | /// If the time phrase in the input natural language phrase describes an interval between two `Date`s, this is that `DateInterval` 29 | private(set) var dateInterval: DateInterval? 30 | 31 | init(inputString: String?, indexOfStartingCharacterOfTimePhrase: Int?, timePhrase: String?, ignoredText: String?, referenceDate: Date?, startDate: Date?, endDate: Date?, dateInterval: DateInterval?) { 32 | self.inputString = inputString 33 | self.indexOfStartingCharacterOfTimePhrase = indexOfStartingCharacterOfTimePhrase 34 | self.timePhrase = timePhrase 35 | self.ignoredText = ignoredText 36 | self.referenceDate = referenceDate 37 | self.startDate = startDate 38 | self.endDate = endDate 39 | self.dateInterval = dateInterval 40 | } 41 | 42 | 43 | } 44 | 45 | // Overriding output of `print(ChronoParsedResult)` to make it more useful 46 | extension ChronoParsedResult: CustomStringConvertible { 47 | 48 | var description: String { 49 | let inputStringDescription = self.inputString?.description ?? "nil" 50 | let indexOfStartingCharacterOfTimePhraseDescription = self.indexOfStartingCharacterOfTimePhrase?.description ?? "nil" 51 | let timePhraseDescription = self.timePhrase?.description ?? "nil" 52 | let ignoredTextDescription = self.ignoredText?.description ?? "nil" 53 | 54 | // Make the dates pretty 55 | let locale = Locale(identifier: "en_US") 56 | let dateFormatter = DateFormatter() 57 | dateFormatter.dateStyle = .long 58 | dateFormatter.timeStyle = .long 59 | dateFormatter.locale = locale 60 | 61 | var referenceDateDescription = "nil" 62 | if let referenceDate = self.referenceDate { 63 | referenceDateDescription = dateFormatter.string(from: referenceDate) 64 | } 65 | 66 | var startDateDescription = "nil" 67 | if let startDate = self.startDate { 68 | startDateDescription = dateFormatter.string(from: startDate) 69 | } 70 | 71 | var endDateDescription = "nil" 72 | if let endDate = self.endDate { 73 | endDateDescription = dateFormatter.string(from: endDate) 74 | } 75 | 76 | var dateIntervalDescription = "nil" 77 | if let dateInterval = self.dateInterval { 78 | let dateIntervalFormatter = DateIntervalFormatter() 79 | dateIntervalFormatter.dateStyle = .long 80 | dateIntervalFormatter.timeStyle = .long 81 | dateIntervalDescription = dateIntervalFormatter.string(from: dateInterval)! 82 | } 83 | 84 | return "inputString: \(inputStringDescription)\nindexOfStartingCharacterOfTimePhrase: \(indexOfStartingCharacterOfTimePhraseDescription)\ntimePhrase: \(timePhraseDescription)\nignoredText: \(ignoredTextDescription)\nreferenceDate: \(referenceDateDescription)\nstartDate: \(startDateDescription)\nendDate: \(endDateDescription)\ndateInterval: \(dateIntervalDescription)" 85 | } 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono iOS/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Sample Apps/ChronoSample/Chrono tvOS/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Chrono/Chrono.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Chrono.swift 3 | // chrono-swift 4 | // 5 | // Created by Neil Sardesai on 2016-11-16. 6 | // Copyright © 2016 Neil Sardesai. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import JavaScriptCore 11 | 12 | /// A singleton that contains methods for extracting date information from natural language phrases. Subclassing is not allowed. 13 | final class Chrono { 14 | 15 | /// Use this property to get the shared singleton instance of `Chrono` 16 | static let shared = Chrono() 17 | private var context: JSContext 18 | 19 | private init() { 20 | // Create JavaScript environment 21 | context = JSContext() 22 | 23 | // Load chrono.min.js 24 | let path = Bundle.main.path(forResource: "chrono.min", ofType: "js") 25 | let url = URL(fileURLWithPath: path!) 26 | var chronoJSSource = try! String(contentsOf: url, encoding: .utf8) 27 | 28 | // Won’t work without this 29 | chronoJSSource = "var window = this;\n \(chronoJSSource)" 30 | 31 | // Evaluate chrono.min.js 32 | context.evaluateScript(chronoJSSource) 33 | } 34 | 35 | // MARK: Convenience Methods 36 | 37 | /** 38 | Attempts to extract a date from a given natural language phrase. The reference date is assumed to be the current system date. 39 | 40 | Example: If the current system date is November 20th, 2016 9:41 AM CST, and the natural language phrase is “2 days ago”, the return `Date` will be November 18th, 2016 9:41 AM CST 41 | 42 | - Parameter naturalLanguageString: The input natural language phrase 43 | 44 | - Returns: A `Date` extracted from the input `naturalLanguageString`. If a `Date` could not be found, returns `nil`. 45 | */ 46 | func dateFrom(naturalLanguageString: String) -> Date? { 47 | let results = parsedResultsFrom(naturalLanguageString: naturalLanguageString, referenceDate: nil) 48 | guard let date = results.startDate else { return nil } 49 | return date 50 | } 51 | 52 | /** 53 | Attempts to extract a date interval from a given natural language phrase. The reference date is assumed to be the current system date. 54 | 55 | Example: If the current system date is November 20th, 2016 9:41 AM CST, and the natural language phrase is “tomorrow from 3-4 PM”, the return `DateInterval` will be November 21th, 2016 3:00 PM CST - November 21th, 2016 4:00 PM CST 56 | 57 | - Parameter naturalLanguageString: The input natural language phrase 58 | 59 | - Returns: A `DateInterval` extracted from the input `naturalLanguageString`. If a `DateInterval` could not be found, returns `nil`. 60 | */ 61 | func dateIntervalFrom(naturalLanguageString: String) -> DateInterval? { 62 | let results = parsedResultsFrom(naturalLanguageString: naturalLanguageString, referenceDate: nil) 63 | guard let startDate = results.startDate, let endDate = results.endDate else { return nil } 64 | return DateInterval(start: startDate, end: endDate) 65 | } 66 | 67 | /** 68 | Attempts to extract a date from a given natural language phrase. A reference date is required. If you want to use the current system date as the reference date, use `dateFrom(naturalLanguageString:)` instead. 69 | 70 | Example: If the reference date is October 18th, 2016 9:41 AM CST, and the natural language phrase is “2 days ago”, the return `Date` will be October 16th, 2016 9:41 AM CST 71 | 72 | - Parameter naturalLanguageString: The input natural language phrase 73 | - Parameter referenceDate: The reference date used to calculate the return `Date` 74 | 75 | - Returns: A `Date` extracted from the input `naturalLanguageString` and calculated based on the `referenceDate`. If a `Date` could not be found, returns `nil`. 76 | */ 77 | func dateFrom(naturalLanguageString: String, referenceDate: Date) -> Date? { 78 | let results = parsedResultsFrom(naturalLanguageString: naturalLanguageString, referenceDate: referenceDate) 79 | guard let date = results.startDate else { return nil } 80 | return date 81 | } 82 | 83 | /** 84 | Attempts to extract a date interval from a given natural language phrase. A reference date is required. If you want to use the current system date as the reference date, use `dateIntervalFrom(naturalLanguageString:)` instead. 85 | 86 | Example: If the reference date is October 18th, 2016 9:41 AM CST, and the natural language phrase is “tomorrow from 3-4 PM”, the return `DateInterval` will be October 19th, 2016 3:00 PM - October 19th, 2016 4:00 PM. 87 | 88 | - Parameter naturalLanguageString: The input natural language phrase 89 | - Parameter referenceDate: The reference date used to calculate the return `DateInterval` 90 | 91 | - Returns: A `DateInterval` extracted from the input `naturalLanguageString` and calculated based on the `referenceDate`. If a `DateInterval` could not be found, returns `nil`. 92 | */ 93 | func dateIntervalFrom(naturalLanguageString: String, referenceDate: Date) -> DateInterval? { 94 | let results = parsedResultsFrom(naturalLanguageString: naturalLanguageString, referenceDate: referenceDate) 95 | guard let startDate = results.startDate, let endDate = results.endDate else { return nil } 96 | return DateInterval(start: startDate, end: endDate) 97 | } 98 | 99 | // MARK: Detailed Parsed Results 100 | 101 | /** 102 | Attempts to extract date information from a given natural language phrase and returns a `ChronoParsedResult` with detailed results about the extracted date information. You can optionally pass in a reference date for date calculations. If no reference date is passed in, the reference date is assumed to be the current system date. 103 | 104 | - Parameter naturalLanguageString: The input natural language phrase 105 | - Parameter referenceDate: The reference date used to calculate date information. If you specify `nil` for this parameter, `referenceDate` is assumed to be the current system date. 106 | 107 | - Returns: A `ChronoParsedResult` with details about extracted date information 108 | */ 109 | func parsedResultsFrom(naturalLanguageString: String, referenceDate: Date?) -> ChronoParsedResult { 110 | context.setObject(naturalLanguageString, forKeyedSubscript: "naturalLanguageString" as NSString) 111 | 112 | if let referenceDate = referenceDate { 113 | // Get year, month, day from referenceDate 114 | context.setObject(referenceDate, forKeyedSubscript: "referenceDate" as NSString) 115 | context.evaluateScript("var results = chrono.parse(naturalLanguageString, referenceDate);") 116 | } 117 | else { 118 | // Reference date is automatically current date if referenceDate is nil 119 | context.evaluateScript("var results = chrono.parse(naturalLanguageString);") 120 | } 121 | 122 | // Position in natural language string where time phrase starts 123 | let index = context.evaluateScript("results[0].index;") 124 | var indexOfStartingCharacterOfTimePhrase: Int? 125 | if index!.description != "undefined" { 126 | indexOfStartingCharacterOfTimePhrase = Int(index!.toInt32()) 127 | } 128 | 129 | // Separate time phrase from rest of input string 130 | let text = context.evaluateScript("results[0].text;") 131 | var timePhrase: String? 132 | var ignoredText: String? 133 | if text!.description != "undefined" { 134 | timePhrase = text!.toString() 135 | 136 | // Filter out (on/in) + (the) + timePhrase 137 | let timePhrasePattern = "(?>\\s*)*(\\bon|\\bin)*(?>\\s*)*(\\bthe)*(?>\\s*)*\(timePhrase!)(?>\\s*[[:punct:]]*\\s*)*" 138 | let timePhraseRegex = try! NSRegularExpression(pattern: timePhrasePattern, options: .caseInsensitive) 139 | ignoredText = timePhraseRegex.stringByReplacingMatches(in: naturalLanguageString, options: [], range: NSRange(0.. Date? { 47 | let results = parsedResultsFrom(naturalLanguageString: naturalLanguageString, referenceDate: nil) 48 | guard let date = results.startDate else { return nil } 49 | return date 50 | } 51 | 52 | /** 53 | Attempts to extract a date interval from a given natural language phrase. The reference date is assumed to be the current system date. 54 | 55 | Example: If the current system date is November 20th, 2016 9:41 AM CST, and the natural language phrase is “tomorrow from 3-4 PM”, the return `DateInterval` will be November 21th, 2016 3:00 PM CST - November 21th, 2016 4:00 PM CST 56 | 57 | - Parameter naturalLanguageString: The input natural language phrase 58 | 59 | - Returns: A `DateInterval` extracted from the input `naturalLanguageString`. If a `DateInterval` could not be found, returns `nil`. 60 | */ 61 | func dateIntervalFrom(naturalLanguageString: String) -> DateInterval? { 62 | let results = parsedResultsFrom(naturalLanguageString: naturalLanguageString, referenceDate: nil) 63 | guard let startDate = results.startDate, let endDate = results.endDate else { return nil } 64 | return DateInterval(start: startDate, end: endDate) 65 | } 66 | 67 | /** 68 | Attempts to extract a date from a given natural language phrase. A reference date is required. If you want to use the current system date as the reference date, use `dateFrom(naturalLanguageString:)` instead. 69 | 70 | Example: If the reference date is October 18th, 2016 9:41 AM CST, and the natural language phrase is “2 days ago”, the return `Date` will be October 16th, 2016 9:41 AM CST 71 | 72 | - Parameter naturalLanguageString: The input natural language phrase 73 | - Parameter referenceDate: The reference date used to calculate the return `Date` 74 | 75 | - Returns: A `Date` extracted from the input `naturalLanguageString` and calculated based on the `referenceDate`. If a `Date` could not be found, returns `nil`. 76 | */ 77 | func dateFrom(naturalLanguageString: String, referenceDate: Date) -> Date? { 78 | let results = parsedResultsFrom(naturalLanguageString: naturalLanguageString, referenceDate: referenceDate) 79 | guard let date = results.startDate else { return nil } 80 | return date 81 | } 82 | 83 | /** 84 | Attempts to extract a date interval from a given natural language phrase. A reference date is required. If you want to use the current system date as the reference date, use `dateIntervalFrom(naturalLanguageString:)` instead. 85 | 86 | Example: If the reference date is October 18th, 2016 9:41 AM CST, and the natural language phrase is “tomorrow from 3-4 PM”, the return `DateInterval` will be October 19th, 2016 3:00 PM - October 19th, 2016 4:00 PM. 87 | 88 | - Parameter naturalLanguageString: The input natural language phrase 89 | - Parameter referenceDate: The reference date used to calculate the return `DateInterval` 90 | 91 | - Returns: A `DateInterval` extracted from the input `naturalLanguageString` and calculated based on the `referenceDate`. If a `DateInterval` could not be found, returns `nil`. 92 | */ 93 | func dateIntervalFrom(naturalLanguageString: String, referenceDate: Date) -> DateInterval? { 94 | let results = parsedResultsFrom(naturalLanguageString: naturalLanguageString, referenceDate: referenceDate) 95 | guard let startDate = results.startDate, let endDate = results.endDate else { return nil } 96 | return DateInterval(start: startDate, end: endDate) 97 | } 98 | 99 | // MARK: Detailed Parsed Results 100 | 101 | /** 102 | Attempts to extract date information from a given natural language phrase and returns a `ChronoParsedResult` with detailed results about the extracted date information. You can optionally pass in a reference date for date calculations. If no reference date is passed in, the reference date is assumed to be the current system date. 103 | 104 | - Parameter naturalLanguageString: The input natural language phrase 105 | - Parameter referenceDate: The reference date used to calculate date information. If you specify `nil` for this parameter, `referenceDate` is assumed to be the current system date. 106 | 107 | - Returns: A `ChronoParsedResult` with details about extracted date information 108 | */ 109 | func parsedResultsFrom(naturalLanguageString: String, referenceDate: Date?) -> ChronoParsedResult { 110 | context.setObject(naturalLanguageString, forKeyedSubscript: "naturalLanguageString" as NSString) 111 | 112 | if let referenceDate = referenceDate { 113 | // Get year, month, day from referenceDate 114 | context.setObject(referenceDate, forKeyedSubscript: "referenceDate" as NSString) 115 | context.evaluateScript("var results = chrono.parse(naturalLanguageString, referenceDate);") 116 | } 117 | else { 118 | // Reference date is automatically current date if referenceDate is nil 119 | context.evaluateScript("var results = chrono.parse(naturalLanguageString);") 120 | } 121 | 122 | // Position in natural language string where time phrase starts 123 | let index = context.evaluateScript("results[0].index;") 124 | var indexOfStartingCharacterOfTimePhrase: Int? 125 | if index!.description != "undefined" { 126 | indexOfStartingCharacterOfTimePhrase = Int(index!.toInt32()) 127 | } 128 | 129 | // Separate time phrase from rest of input string 130 | let text = context.evaluateScript("results[0].text;") 131 | var timePhrase: String? 132 | var ignoredText: String? 133 | if text!.description != "undefined" { 134 | timePhrase = text!.toString() 135 | 136 | // Filter out (on/in) + (the) + timePhrase 137 | let timePhrasePattern = "(?>\\s*)*(\\bon|\\bin)*(?>\\s*)*(\\bthe)*(?>\\s*)*\(timePhrase!)(?>\\s*[[:punct:]]*\\s*)*" 138 | let timePhraseRegex = try! NSRegularExpression(pattern: timePhrasePattern, options: .caseInsensitive) 139 | ignoredText = timePhraseRegex.stringByReplacingMatches(in: naturalLanguageString, options: [], range: NSRange(0.. 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | Default 511 | 512 | 513 | 514 | 515 | 516 | 517 | Left to Right 518 | 519 | 520 | 521 | 522 | 523 | 524 | Right to Left 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | Default 536 | 537 | 538 | 539 | 540 | 541 | 542 | Left to Right 543 | 544 | 545 | 546 | 547 | 548 | 549 | Right to Left 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | --------------------------------------------------------------------------------