captains-log

[TO-FIX] audiojournaling app
git clone git://git.figbert.com/captains-log.git
Log | Files | Refs

commit 833bece6de6078cf2baea2121df54f1966eb26d2
parent caf00e351eac7090856bb7098028a99276fc543b
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Fri, 18 Oct 2019 10:45:48 -0700

Adding stardate feature

Diffstat:
McaptainsLog/ContentView.swift | 42++++++++++++++++++++++++++++++++++++++++--
1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/captainsLog/ContentView.swift b/captainsLog/ContentView.swift @@ -12,7 +12,37 @@ struct ContentView: View { @State private var recording = false @State private var timeElapsed = 0.00 @State private var timer:Timer? - + @State private var msg = "" + var stardate: Double = { () -> Double in + let date = Date() + let calendar = Calendar.current + let year = calendar.component(.year, from: date) + let month = calendar.component(.month, from: date) + let day = calendar.component(.day, from: date) + let leapyear = !(year % 100 == 0) && year % 4 == 0 + let months = [ + 1: 0, + 2: 31, + 3: !leapyear ? 59 : 60, + 4: !leapyear ? 90 : 91, + 5: !leapyear ? 120 : 121, + 6: !leapyear ? 151 : 152, + 7: !leapyear ? 181 : 182, + 8: !leapyear ? 212 : 213, + 9: !leapyear ? 243 : 244, + 10: !leapyear ? 273 : 274, + 11: !leapyear ? 304 : 305, + 12: !leapyear ? 334 : 335 + ] + let n = !leapyear ? 365 : 366 + let b = 2005 + let c = 58000.0 + let monthValue = Double(months[month] ?? 0) + let stageOne = Double(1000*(year-b)) + let stageTwo = (1000.0/Double(n))*(monthValue + Double(day) - 1.0) + return Double(round(100*(c + stageOne + stageTwo))/100) + }() + var body: some View { VStack { Spacer() @@ -22,6 +52,13 @@ struct ContentView: View { if (self.recording) { self.timer = Timer.scheduledTimer(withTimeInterval: 0.01, repeats: true, block: { timer in self.timeElapsed += 0.01 + if (self.timeElapsed <= 1) { + self.msg = "Captain's log" + } else if (self.timeElapsed) <= 3 { + self.msg = "stardate \(self.stardate)" + } else { + self.msg = "" + } }) } else { self.timer?.invalidate() @@ -44,7 +81,8 @@ struct ContentView: View { } Spacer() VStack { - Text("Stardate") + Text("\(self.msg)") + .font(.system(size: 24, weight: .regular, design: .rounded)) Image(uiImage: UIImage(systemName: "waveform", withConfiguration: UIImage.SymbolConfiguration(pointSize: CGFloat.init(50), weight: .medium, scale: .large))!) } Spacer()