SwiftUI DatePicker and Date wrong timezone, not using the local one - swiftui

I am implementing a DatePicker in SwiftUI.
#State var dateTime = Date()
DatePicker("Date and time, selection: $dateTime)
However, when I select a date & time there and try to print the result I get a different time.
print(self.dateTime.description(with: .current))
print(self.dateTime)
The idea is that if I select 10:28 PM, the first line with .current returns the selected value, but as a String and the second one returns a completely different value, usually with some hours added which I think it takes by default UTC+0 or something, I am now in GMT+3.
I think I have read a lot of answers in the past hour but nothing exactly about this. Any idea is much appreciated.

Related

Is there a way to check the value of the cell to the left and add two to the count, unless there is a value entered in another cell in the same row?

I am trying to write a piece of code in Google Sheets that automatically creates a follow-up date based on the date in the immediate left cell. It gets that date, and adds two (days) to it. Then that date gets pushed into Appsheet, where it is marked on a virtual calendar.
I also want the code to recognize when something is filled into the "Status" section (which is located in the 4th cell to the right) and fill in the current cell with something like "Done".
Currently, everything I have works except for that last part, when something is entered into the Status column I get an error that reads;
Function IF parameter 1 expects boolean values. But 'Declined' is a
text and cannot be coerced to a boolean.
I believe that means I need to convert the data in the status column into a boolean value, but I have no idea how to proceed in doing that. See below code;
=IF(INDIRECT("RC[4]",0), "Done", INDIRECT("RC[-1]",0) +2)
Let me know what you guys think, and thank you in advance for your help 👍
try:
=IF(INDIRECT("RC[4]",0)="Declined", "Done", INDIRECT("RC[-1]",0) +2)
or:
=IF(INDIRECT("RC[4]",0)<>"Declined", "Done", INDIRECT("RC[-1]",0) +2)

Google Sheets: Sum a Value Range Within a Specified Time Frame

I'm trying to sum a range of values, within a given time frame. The time frame could be x hours, or y days, etc. An example:
So for each row, I need to sum the last hours or days as specified in cells C2:E2, which are numeric (just added formatting to show the text). Note that the datetime values do not follow any interval pattern, but are always sequential.
Although I've tried searching SO, and via Google, I haven't been able to find a way to do this.
Any suggestions would be very welcome.
[Edit]
I've added to a link to an example sheet of what I'm trying to do... pls just ask if I can add any further info!
Test Sum By Time
try:
=SUMIFS(B3:B, A3:A, ">="&NOW()-1)
=SUMIFS(B3:B, A3:A, ">="&NOW()-7)
In Google sheets, use the =TODAY() code to for today's date and put this in another cell. You could always create a new sheet (which we will call sheet3) which you hide afterwards. Let's imagine you put this in cell A1.
You can use the =IMPORTRANGE("the google sheets website link", "Sheet Name!A3:A31" to insert the values. Let's imagine you import this into B3:B31. In C3, you put =IF(REGEXMATCH(B3, A1), 1, 0).
You continue this in each cell from B4:B31, each time changing "B3" to the current row number. Then we can use the =SUM(C3:C31) code to count how many meet this condition. Let's imagine you put this in A2.
Now back to the original sheet. Use `=IMPORTRANGE("the google sheets website link", "sheet3!A2" in the cell C3.
For the other 2, I don't know, sorry!

Previous day in Postman request

I have below code in postman's pre-request script --which gives me current date. I rather want yesterday's date (current_timestamp - 1 day).
var current_timestamp = new Date();
postman.setEnvironmentVariable("current_timestamp", current_timestamp.toISOString());
I searched doc & net but could not get the answer. Can someone please help me with reference to date functions --to get my desired result.
Thanks
You can use the momentjs module in Postman to get a date in any format you need.
In the Pre-Request Script, add this to get what you need without using native JS:
var moment = require('moment')
pm.environment.set("current_timestamp", moment().toISOString())
pm.environment.set("current_timestamp - 1 day", moment().subtract(1, 'day').toISOString())
This snippet will bring in the module and set the dates you require in the environment file.
For a non moment solution in plain JavaScript to just quickly go back 24hrs, you could do something like this:
var yesterday = (Date.now() - 86400000) // 24hrs in ms
pm.environment.set('yesterday', new Date(yesterday).toISOString())
Both solutions would give you the same outcome but I prefer to use moment as it's a built-in module that handles dates and times very well.

NSDate for current date is different?

I was trying to get the next date when I noticed something interesting to me. When I do
let date = NSDate()
let calender = NSCalendar.current
let components = calender.dateComponents([.year, .month, .day], from: date as Date)
dateLabel.text = "\(components.month!)/\(components.day!)/\(components.year!)"
I get thedate I want, which is the current date.
However, when I do
#IBAction func nextDate(_ sender: UIButton) {
var oneDayfromNow: NSDate {
return NSCalendar.current.date(byAdding: .day, value: 1, to: NSDate() as Date)! as NSDate
}
print("Current Date: \(calender)")
print(oneDayfromNow)
}
on my print with the current date I actually get the next date's date and my oneDayfromNow variable is the date 2 days from now. So in short, my current date for my two blocks are different.
Can someone explain to me why is that?
THanks
Here is a quote from apple developer website about NSDate,
NSDate objects encapsulate a single point in time, independent of any
particular calendrical system or time zone. Date objects are
immutable, representing an invariant time interval relative to an
absolute reference date (00:00:00 UTC on 1 January 2001).
So, it means that it does not dictate time in any particular region, rather it is an opaque object which denotes some particular time. It is rather the responsibility of NSDateFormatter to format date and represent it to the timezone that you want it in.
You know I used to recognize something similar. All my Date values were always 8 hours ahead (I live in Northern California).
Check out something called "ISO 8601"
ISO 8601 - Wikipedia
I don't know if you're familiar with Zulu time or what's now known as UTC (Universal Time Coordinates I think), but it's a universal time that ignores time zones.
You're probably still getting the correct date and time, they are just reflected with UTC.

how to give time format in rails query?

Mysql table one row =>
id = 1
time = "21:00" //datatype => TIME
name = "xyz"
while i am fetching the data
#person = #person.all
[#<persons id: 1, time: "2000-01-01 21:00:00, name: "xyz", created_at: "2014-03-19 05:13:43", updated_at: "2014-03-19 05:13:43", creator_id: nil">
#person[0].time # 2000-01-01 21:00:00
It should be "21:00" Right?
Why i am getting "2000-01-01 21:00:00" output any suggestion ??
After fetching data from query, you can format to time for displaying:
fetch all the records:
#person = #person.all
format to time.
#person.first.time.strftime("%H:%M")
for getting more information about date and time formating click here
#person[0].time returns the Ruby Time object for that value, which includes date. If you're outputting it directly to the console or browser window, Ruby is converting it to a default string representation of the Time object which, again, includes the date.
To format the time for display, you'll want to look at your options for date/time formatting using Rails' internationalization API.
try using strftime - it lets you specify format
ie something like:
#person[0].time.strftime("%m/%d/%Y %H:%M:%S")
Changing datatype from TIME TO VARCHAR :
It is not good approach. I think you should consider all the case about time, there is a lot possibility where you required TIME object to other operation like date.
If you store hours and minutes in VARCHAR then you can not perform any operation like TIME object. please think about, if you required hours or date from database in future but you have store only hours and minutes in database, you did not store (TIME Object)it, then it will be considered bad approach and failure.
you store TIME at the place of hours and minutes then It is good cause for future perspective.
If you store time object then you are store additional information with hours and minutes. If you will required Date, time, hours, minutes and even seconds then you can calculate by time formating.
If you store time then there is only one extra effort time formating that is negligible in perspective of performance.
To store TIME Object instead of hours and minutes in string format is always better.