Mercurial > public > lazybear
comparison LazyBear/Global functions/GetDateComponents.swift @ 411:681fb377235e
Implementing insider transactions
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Mon, 07 Jun 2021 20:59:52 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
410:e24c9ca71824 | 411:681fb377235e |
---|---|
1 // | |
2 // GetDateComponents.swift | |
3 // LazyBear | |
4 // | |
5 // Created by Dennis Concepción Martín on 7/6/21. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 enum Components { | |
11 case day, month, year | |
12 } | |
13 | |
14 /* | |
15 Get components from a date | |
16 */ | |
17 func getDateComponents(_ components: Components, _ date: Date) -> String { | |
18 let dateComponents = Calendar.current.dateComponents([.year, .month, .day], from: date) | |
19 | |
20 switch components { | |
21 case .year: | |
22 return "\(dateComponents.year ?? 2020)" | |
23 case .day: | |
24 return "\(dateComponents.day ?? 1)" | |
25 case .month: | |
26 let dateFormatter = DateFormatter() | |
27 let monthNumber = dateComponents.month ?? 1 | |
28 let monthLetters = dateFormatter.shortMonthSymbols[monthNumber-1] | |
29 | |
30 return "\(monthLetters)" | |
31 } | |
32 | |
33 } |