Mercurial > public > lazybear
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Global functions/GetDateComponents.swift Mon Jun 07 20:59:52 2021 +0200 @@ -0,0 +1,33 @@ +// +// GetDateComponents.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 7/6/21. +// + +import SwiftUI + +enum Components { + case day, month, year +} + +/* + Get components from a date + */ +func getDateComponents(_ components: Components, _ date: Date) -> String { + let dateComponents = Calendar.current.dateComponents([.year, .month, .day], from: date) + + switch components { + case .year: + return "\(dateComponents.year ?? 2020)" + case .day: + return "\(dateComponents.day ?? 1)" + case .month: + let dateFormatter = DateFormatter() + let monthNumber = dateComponents.month ?? 1 + let monthLetters = dateFormatter.shortMonthSymbols[monthNumber-1] + + return "\(monthLetters)" + } + +}