How to get the current time during the simulation - anylogic

I would like to display the current time during my simulation so that I can simulate with full screen and also have the time. I tried the function getMinute(Date date) and a variable date. I didn't get an error but I also didn't get the time. Is it also possible to have a clock which displays the time?

You can do this:
String.format("%02d:%02d",getHourOfDay(), getMinute())
This will give you a string with the current time during the simulation
You can also use the clock object in the pictures palette to display time
you can use date() to know the date and time

Related

How to reset time for data logging in micro:bit micropython

I would like to start data logging in a bbc micro:bit with the press of its button_a, in order to be able to synchronize the timestamps with an external clock.
The idea is that, if I press the button at 12:10 o'clock, I would know that the first row of data (with 0.00 timestamp) was taken at that time (+/- human reaction time, of course).
The problem is that the zero time of the timestamps begin when the bbc micro:bit is turn on (or reset); so the first timestamp in the log file is not 0.00.
Of course, I could synchronize with that turning-on, but I think it would not be that accurate (I'm using the micro:bit with a robotbit board, which has a big 'on-off' switch.)
What I would like would be some kind of reset_time() method. :)
The code is this:
from microbit import *
import log
log.set_labels('altitude', 'azimuth', 'measure', timestamp=log.SECONDS)
# Wait until Button 'A' is pressed. This way, we can sinchronize the measures with an external clock or watch
while not button_a.was_pressed():
pass
for altitude in...
for azimuth in...
measure=take_reading()
log.add({
'altitude': altitude,
'azimuth': azimuth,
'measure': measure
})
The full code is here: https://github.com/lopezsolerluis/foto-teodolito-log

UIDatePicker count Down timer mode doesn't return the correct time in Xcode 10.3

I'm working on a project in which the user can select a time interval (HH:mm) from a UIDatePicker in count down mode and, with that time interval, I want to trigger a notification.
I created the UIDatePicker in the Storyboard and set the Mode to Count Down Timer in the Attributes Inspector.
The problem is that when I get the current value of the datePicker, the value is never correct.
For example, if the user selects 1 minute, I get random values between 70 an 110 but never 60!
How is this possibile?
(The problem occurs with every selection)
This is how I get the current value:
timePicker.countDownDuration
and for testing purpose, I print it with
timePicker.countDownDuration.description
Maybe there is a bug or something that I don't know? (of course there is)
I tried to convert the value represented on the UIDatePicker in string a then, reconvert it in TimeInterval but if there is a better method it would be great.
Ok problem solved, maybe it's a bug of XCode.
The problem occurs when you build the datepicker from storyboard and set it's mode paramether to Count Down Timer.
To solve this problem, simply don't set the mode of the datepicker on count down timer from the storyboard but you need to set the mode programmatically with
timepicker.datePickerMode = .countDownTimer
Doing this, the problem is solved

How do I "add" time to firebase timestamp in Swift?

This question is best stated in an example:
It is currently 9:00am. User wants to do activity at 4:00pm the following day. They use UIDatePicker to select 4:00pm the next day, and then hit a button. I know firebase does times in milliseconds from 1970, so what I want to do is "add" the number of milliseconds from 9:00am to 4:00pm the following day to the ServerValue.timestamp(), like so:
activitiesRef.child(newActivity.id).setValue([
"id": newActivity.id,
"name": newActivity.name,
"isActive": newActivity.isActive,
"locString": newActivity.locationString,
"locLat": newActivity.locLat,
"locLong": newActivity.locLong,
"privacySetting": newActivity.privacySetting,
"targetTime": ServerValue.timestamp()]) // + some added value of time
//"targetTime": [".sv": "timestamp"]])
The reason for this is because I will be displaying a countdown timer elsewhere in the app until it reaches the targetTime. If I can push to firebase the targetTime, then the countdown timer will be a simple comparison of the current time on the user's phone to the targetTime itself.
The error I keep getting when trying to add a double value to the ServerValue.timestamp() is "Contextual type 'Any' cannot be used with dictionary literal"
If it is not possible to do so, what other options do I have? Thank you.
ServerValue.timestamp() is not a number that you can use to perform date arithmetic. It's a special placeholder value that the server side interprets with its sense of time.
The best you can do is write the timestamp, read it back out as a number, then perform math on it.

Specify starting time of track within URL for SoundCloud?

Anyone know if there's a way to generate URL's for SoundCloud tracks that specify a start time for the song? I'm looking for a way to force playback of streams at a certain time in the stream without having to do any processing on my end via the API.
As #bsz correctly noticed, we have released a way of specifying start time on the sound when linking to it, append #t=12s to the sound's URL to start it at 12th second, etc.
If the audio is long enough, you can use (e.g.) #t=2h10m12s.
They seem to have added a #t option but not sure if you can also give an stop time:
https://soundcloud.com/razhavaniazha-com/06-06-2013-razhavaniazha-afn#t=54:00
You can also specify a start time one minute or over by appending
#XmXs
If you want a time right on the minute mark (e.g. 3:00), include 0 seconds (0s) in the time code (i.e. 3m0s), or else the start time will be ignored. It does not appear to support a start time over an hour.
Click share and set or pick time

UIDatePicker, time, and 1970

I've come across a small issue that I've been chewing on for a day or two now.
Using the Apple example project called DateCell I lifted its UIDatePicker and set it to time. I used this particular code as it did the animated slide on/off the screen.
My workflow is to set four values, start time, lunch time out, lunch time in, and stop time. I set these values by using [NSDate date].
I then use NSCalander:component calls to do some math such as "add 30 minutes to start time to get lunch time out," and "start time - lunch time out - 8 hours to get stop time."
The initial setup goes just fine. Clicking on the start time cell brings up the picker, and selecting a time change the other three times following my simple math formula's.
If the second row is selected, the lunch time out, the wheel comes up again to pick your lunch time out time. However this is where my problems start. It seems that my UIDatePickerModeTime wheel returns a date portion for January 1, 1970. And its this date portion that messes up my math formulas.
My question is, what can I do to fix this?
I've tried setting an initial, minimum time, in the XIB for the picker. This sort of works but when you pick a time on the wheel, the wheel spins itself to the time set in the XIB. This method doesn't have a clean feel to it.
I've tried settings the initWithTimeInterval class methods, but these block out times and isn't what I'm looking for I think.
I've also tried the NSDateFormatter:stringFromDate|dateFromString calls, and these had no affect.
What I have not done yet:
Custom defined date/time string.
Rebuilding UIDatePicker:Time from scratch
Am I over looking anything?
Thanks.
I've solved my problem, and here is how I addressed it.
Before I get to my answer I'm still really new to Objective-C and object oriented programming so my vocabulary doesn't know how to describe some of the things I've tried explaining. So take this into account when reading this.
Using UIDatePicker in time mode, i.e. you go into your NIB/XIB file and set your UIDatePicker object to 'time', will only return time. This is where I went wrong.
Using the NSDateComponent or any of the NSCalendar methods will bring out the date component of the picker. Thus you'll see January 1st, 1970 in the NSLog returns for example.
I had to find a new way of doing my math and manipulation of the times I was getting from the picker.
What I ended up using is NSTimeInterval, dateByAddingTimeInterval, and timeIntervalSinceDate. Research showed that NSTimeInterval is also a float type, so I used float to do some math as well.
Here an example -
if (indexPath.row == [labelArray indexOfObjectIdenticalTo:#"Clock Out"])
{
NSTimeInterval diffClockInOutToLunch = [outToLunch timeIntervalSinceDate:clockIn];
float remainingInTheDay = 28800 - diffClockInOutToLunch;
self.clockOut = [inFromLunch dateByAddingTimeInterval:remainingInTheDay];
cell.detailTextLabel.text = [self.dateFormatter stringFromDate:clockOut];
self.clockOutIndex = indexPath;
return cell;
}
I'm using a TableView to display my fields. When this 'if' statement is tripped it will populate the detailTextLabel of the line displaying "Clock Out." Visually the phrase "Clock Out" will be on the left side of the row, the time will be on the right side.
diffClockInOutToLunch is defined as a NSTimeInterval type. The operation being performed is timeIntervalSinceDate which essentially subtracts the value of outToLunch from the value of clockIn. Imagine outToLunch as being 11:00pm and clockIn as being 6:00am. This difference is 5 hours. NSTimeInterval stores values as seconds only so this difference of 5 hours is 18000 seconds.
I then perform a normal math operation using float. In this case I want to find out how many hours remain in the work day. This assumes the hours worked in a day is 8 hours. Because NSTimeInterval returns seconds, I converted 8 hours into seconds (28,800 seconds) and then subtract diffClockInOutToLunch from 28800. Now remainingInTheDay is equal to to 10800, or 3 hours.
The next operation I perform is set clockOut to the time our work day is finished. To do this I use the dateByAddingTimeInterval operation, which also is a NSDate method, so whatever it returns will be in a date/time format. In this operation we add remainingInTheDay (10,800 seconds) to inFromLunch (11:30am for example). Our clockOut time is now 2:30pm which is then sent through my DateFormatter and returned as a string to the cell of the TableView and also stored for later use.
Here's another example, from further down in my code -
- (void)clockInChanged
{
// Set clockIn value
self.clockIn = self.pickerView.date;
// Change the outToLunch time
self.outToLunch = [self.pickerView.date dateByAddingTimeInterval:5*60*60];
UITableViewCell *outToLunchCell = [self.tableView cellForRowAtIndexPath:outToLunchIndex];
outToLunchCell.detailTextLabel.text = [self.dateFormatter stringFromDate:outToLunch];
// Change the inFromLunch time
self.inFromLunch = [outToLunch dateByAddingTimeInterval:30*60];
UITableViewCell *inFromLunchCell = [self.tableView cellForRowAtIndexPath:inFromLunchIndex];
inFromLunchCell.detailTextLabel.text = [self.dateFormatter stringFromDate:inFromLunch];
// Change the clockOut time
NSTimeInterval diffClockInOutToLunch = [outToLunch timeIntervalSinceDate:clockIn];
float remainingInTheDay = 28800 - diffClockInOutToLunch;
self.clockOut = [inFromLunch dateByAddingTimeInterval:remainingInTheDay];
UITableViewCell *clockOutCell = [self.tableView cellForRowAtIndexPath:clockOutIndex];
clockOutCell.detailTextLabel.text = [self.dateFormatter stringFromDate:clockOut];
}
In this example, we've previously determined that the row pertaining to "Clock In" time was selected ("Touch Up Inside" if you will) and we drop to this method.
What happens in this method is whenever clockIn is changed using the picker, the times displayed in outToLunch, inFromLunch, and clockOut automatically update and are displayed.
This example shows that we capture the value on the picker (self.pickerView.date) as clockIn. We then use clockIn to seed our mess of dateByAddingTimeInterval's and so forth.
So. This is how I managed my times using UIDatePicker (which is set to time mode).
The short answer would be I was using the wrong methods to work with what my picker was turning.
I hope this helps you and hopefully it'll be here if I need it again too ;)