How to make a duration picker react native - react-native

I am trying to build a duration picker:
it would look like a simple ios time picker, but it would start with 0 minutes and 0 seconds and go up to 23 hours and 59 minutes.
I tried using normal DateTimePickers (react native date picker), and using the 24 hours format, and that would work. The problem is that ios doesn't support the 24 hours format.
PS: the 12 hours format, as you can see from the image, starts from 1 hour and 0 minutes, so that would not be good if someone would want to take 20 minutes, for example.
It would look something like this, but in 24 hours format, starting from 0 hours and 0 minutes, and going till 23 and 59 minutes.

I found a way to implement this:
I used another library (react-native-modal-datetime-picker) and, as said in the docs, you can't set a 24 hours format on ios, but what you can do is setting
locale="en_GB"
Using this you can now achieve this look:
As you can see you will be able to choose even times with 0 hours.
To get the minutes, on the Date object you will get as a prop of onConfirm, do this:
const minutes = date.getMinutes() + date.getHours() * 60;
console.log(minutes);
Finally, if you want your DurationPicker to start at 0 0, set the prop date to a date with 0 hours and 0 minutes.
At the end it is going to look something like this:
<DateTimePicker
mode='time'
date={new Date(new Date().setHours(0, 0, 0, 0))}
locale='en_GB'
{...props}
/>

Related

Basic DateTime Algebra

How do i go about writing some basic algebra math in vb.net?
Example:
I need to schedule a process to run 60 days before start date of an object.
When my process runs I do:
Now(UTC) - StarDate(UTC) = days diff
If days diff less than 60, i run my process immediately.
If its over 60 days, i need to schedule my process to run again in 60 days.
So this leaves me with:
X - [daysDiff] = 60
I know how to solve this on paper but not in vb.net code.
Example:
X - 107 = 60
add 107 to each side, i have my # of days to add (107)
How do i accomplish this in VB.net?
If you want to know when to run it: if it's over 60 days, then subtract 60 from that value, that will tell you when when to check again.... so if you do the initial check and it comes back 61 days different, it's over 60, so you subtract 60, leaving 1. So now you know you need to schedule it in 1 day. If you do the initial check and it comes out 107, you subtract 60 and the result is 47... so you know in 47 days, you need to run it again as that will be 60 days out. It's two simple steps.

Time comparison and difference in vb

How to compare between current time and a past time in vb and check if the duration time is less than 30 mins or not ?
Example :
Current time : 11:30am
Time : 11:00am
Duration : 30 min (time should be less than 30 mins. )
If the time duration is exactly 30 min difference
Return true
Else false
If (Date.Now - myDateTime) < TimeSpan.FromMinutes(30) Then
'Time difference is less than 30 minutes.
End If
In that case, myDateTime may have been the value of Date.Now that you stored earlier or it may have been constructed in some other way.
Hmmm... I read the question again and it seems that you contradict yourself. First you say that you want to know whether the difference is less than 30 minutes and then you say that you want to return True if the difference is exactly 30 minutes. Perhaps you could make up your mind and get back to us because it's hard to provide a single answer to two contradictory questions.

Display hours in 2 digit format

I am adding hours to the datetime object in sybase.
dateadd(hh,4,date_val)
The problem is that if the current hour is 2am, after adding 4 hours it is displaying 6 instead of 06. How do i achieve the appending of 0 if the time is in single digit? Please help.

Timespan to display just the days, without hrs, min, and sec

Timespan to display just the days, without hrs, min, and sec.
my time span is coming like 30.00:00:00 for 39 days. please help in vb.net code.
Here is the TimeSpan documentation on MSDN. Assuming you start with this:
' Define an interval of 3 days, 16+ hours.
Dim interval As New TimeSpan(3, 16, 42, 45, 750)
Console.WriteLine(interval.Days())
Console.WriteLine(interval.ToString("dddd"))
You have two options for displaying time in days. The first is:
Console.WriteLine(interval.Days())
or you can format your time in the ToString function:
Console.WriteLine(interval.ToString("dddd"))
You would need to add as many ds as you are expecting to display or you will get an error.

How to register every day local notification at certain time?

How can I realize everyday local notifications in my app? So at first run I need to register first local notification at 14:00 and then everyday at 14:00 notification should appear.
User can change this time in app's settings.
How to do this mechanism?
You need to handle the notifcations on your end, but to make a timer that countsdown to a certain time every day, you would need to do something like this:
local targetDate = os.time{ year=2014, month=11, day=8, hour=0, sec=0 } -- Get the date that you want to count down to, in seconds
local text = false
local function enterFrame(event)
if text then text:removeSelf() end -- Everyframe, remove the old text object
local timeRemaining = (targetDate-os.time()) -- Take the difference between the target time and the current time
local days = timeRemaining / 86400 -- get the number of days left by dividing the remaining seconds by the number of seconds in a day
local hours = days%1 * 24 -- get the number of hours left by multiplying the remainder by the number hours in a day
local minutes = hours%1 * 60 -- get the number of minutes by multiplying the remainder by the number of minutes in an hour
local seconds = math.floor( minutes%1 * 60 + 0.5) -- multiply the remainder one more time by the number of seconds in a minute, and round to the nearest second.
-- make a new text object to display all the info
text = display.newText( "Will be available in "..math.floor(days).." days "..math.floor(hours).." hrs "..math.floor(minutes).." mins "..seconds.." secs ", 25, 140)
end
Runtime:addEventListener( "enterFrame", enterFrame )
You can repurpose your code to work with your project, but you need to use OS time and do certain calculations to each variable in order to get the time. Good luck.