Skip to content

Commit

Permalink
Added docblocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettRToomey committed Jan 16, 2017
1 parent 03ec583 commit 9203a6f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Sources/MySQL/MySQL+Date.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import Foundation

public enum MySQLDateError: Swift.Error {
/**
Date wasn't a proper DATETIME-formatted String.
*/
case invalidDate
}

extension Date {
/**
Instantiates a `Date` from a MySQL DATETIME-formatted String.

- Parameters:
- mysql: yyyy-MM-dd HH:mm:ss
*/
public init(mysql date: String) throws {
guard let date = dateFormatter.date(from: date) else {
throw MySQLDateError.invalidDate
Expand All @@ -13,11 +22,15 @@ extension Date {
self = date
}

/**
A MySQL DATETIME formatted String.
*/
public var mysql: String {
return dateFormatter.string(from: self)
}
}

// DateFormatter init is slow, need to reuse
private var _df: DateFormatter?
private var dateFormatter: DateFormatter {
if let df = _df {
Expand Down

0 comments on commit 9203a6f

Please sign in to comment.