Skip to content

Commit

Permalink
Move date formatter expression from AST lib to gen
Browse files Browse the repository at this point in the history
Let's keep the AST lib generic, useful in
other projects.
  • Loading branch information
helje5 committed Nov 11, 2024
1 parent 105982c commit ebeafe2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
24 changes: 0 additions & 24 deletions Plugins/Libraries/LighterCodeGenAST/Nodes/Expression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,30 +301,6 @@ public extension Expression {
}


// MARK: - Date Formatting Convenience

public extension Expression {
static func formattedCurrentDate(format: String) -> Self {
.inlineClosureCall([
.let("fmt", is: .call(name: "DateFormatter")),
.set(instance: "fmt", "locale",
.call(name: "Locale", parameters: [
("identifier", .string("en_US_POSIX"))
])),
.set(instance: "fmt", "timeZone",
.call(name: "TimeZone", parameters: [
("secondsFromGMT", .integer(0))
])),
.set(instance: "fmt", "dateFormat", .string(format)),
.return(.call(instance: "fmt",
name: "string",
parameters: [
("from", .call(name: "Date"))
]))
])
}
}

#if swift(>=5.5)
extension Expression : Sendable {}
extension FunctionCall : Sendable {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,28 @@ extension EnlighterASTGenerator {
}
}
}

// MARK: - Date Formatting Convenience

fileprivate extension Expression {

static func formattedCurrentDate(format: String) -> Self {
.inlineClosureCall([
.let("fmt", is: .call(name: "DateFormatter")),
.set(instance: "fmt", "locale",
.call(name: "Locale", parameters: [
("identifier", .string("en_US_POSIX"))
])),
.set(instance: "fmt", "timeZone",
.call(name: "TimeZone", parameters: [
("secondsFromGMT", .integer(0))
])),
.set(instance: "fmt", "dateFormat", .string(format)),
.return(.call(instance: "fmt",
name: "string",
parameters: [
("from", .call(name: "Date"))
]))
])
}
}

0 comments on commit ebeafe2

Please sign in to comment.