-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile-utils.swift
More file actions
29 lines (25 loc) · 959 Bytes
/
File-utils.swift
File metadata and controls
29 lines (25 loc) · 959 Bytes
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
//
// File-utils.swift
//
// Copyright 2023 OpenAlloc LLC
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
import Foundation
public func generateTimestampFileName(prefix: String, suffix: String, timestamp: Date = Date.now) -> String {
let df = ISO8601DateFormatter()
// unable to get this implementation working yet
// let dateStr = df.string(from: timestamp)
// let regex = /[^0-9]/
// let cleanStr = dateStr.replacing(regex, with: "")
// return "\(prefix)\(cleanStr)\(suffix)"
// primitive implementation
return prefix +
df.string(from: timestamp)
.replacingOccurrences(of: ":", with: "")
.replacingOccurrences(of: "T", with: "")
.replacingOccurrences(of: "Z", with: "")
.replacingOccurrences(of: "-", with: "") + suffix
}