Post

Replies

Boosts

Views

Activity

Convert date "HH" to Int?
Hi! I want to fetch current date in format "HH" and convert it to Int so that i can use it in calculations. I have managed to set the current date to update regularly, and format it to "HH" in a string, but now I am stuck... I need the number of hours between 06:00 -> now, but if now<10 i need number of hours between 06:00 yesterday -> now. Any help is much appreciated! import SwiftUI import Foundation struct ContentView: View {     @State var date = Date()     @State var vekt = Int(70)     @State var temp = Double(37.0)     @State var infusjon = Int(0)     @State var medVaske = Int(0)     @State var sag = Int(0)     @State var blodning = Int(0)     @State var urin = Int(0)     var sagIn: Int{sag*250}     var totIn: Int{infusjon+medVaske+(sag*250)}     var totUt: Int{urin+blodning}     var totUtKorr: Int{urin+(blodning*3)}     var body: some View {         ScrollView{             VStack{                 Text("Væskebalanse") .font(.title)                 Text(timeString(date: date)).onAppear(perform: {let _ = self.updateTimer})             }         }     }     var timeFormat: DateFormatter {         let formatter = DateFormatter()         formatter.dateFormat = "HH"         return formatter     }     func timeString(date: Date) -> String {          let time = timeFormat.string(from: date)          return time     }     var updateTimer: Timer {          Timer.scheduledTimer(withTimeInterval: 1, repeats: true,                               block: {_ in                                  self.date = Date()                                })     }     //----HOW TO??-----let klokke = Int(timeString(date: String)) } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } }
2
0
768
Nov ’21
How to get number of hours between 06:00 -> now?
Hi! Im working on an app to calculate a patients postoperative fluid balance. One of the losses is perspiration, which is calculated as 10ml/kg/h. The day-cycle on the hospital is 06:00 - 05:59, and my plan is to have a button that, when being tapped, calculates the fluid balance from 06:00 at day of surgery, to the moment the button is "activated". As long as the the date when you tap the button is the same date as day of surgery, this should be relatively easy, but the problem is when the night shift calculates fluid balance in the morning before transfer (around 05:00, which would return 23 hours). Or if the night shift is busy and do the calculation like 06:30, which would return 24,5 hours. I have no way of getting the date of surgery (except from asking the user to fill it in, but that would not be as elegant). Is there any way of achieving this? Or should I surrender and just ask the user for date of surgery? Hope the use case was understandable and any help is much appreciated!
1
0
322
Nov ’21