FlipClock.js is incrementing seconds by 2 - flipclock

Interesting behavior in FlipClock library (http://flipclockjs.com/)
The following code works fine:
clock1 = $('.clock1').FlipClock( {
clockFace: 'TwentyFourHourClock'
});
However, if you include an adjustment for timezone, then it starts incrementing seconds by 2:
clock1 = $('.clock1').FlipClock(3600 * 3, {
clockFace: 'TwentyFourHourClock'
});
Any help on this would be appreciated!

Related

How can i increase only 1 microsecond to DateTime.now() in dart

i have the following
Dateime.now() + here i need to increase only 1 microsecond
so wanted output is Dateime.now() + that incensement which is 1 microsecond
i tried the following but it does not work
print(DateTime.now()+const Duration(microsecond : 1);)
How can i implement this
This well get it done.
final now = DateTime.now();
final later = now.add(const Duration(millisecond: 1));
check docs here
Or do it in a single line:
DateTime now = DateTime.now().add(Duration(milliseconds: 1));
print(now);
DateTime does not define an operator +, but it does have an add method that accepts a Duration. (You also have a couple of syntax errors in your code; the semicolon is misplaced, and the named parameter to Duration is microseconds, not microsecond.)
If you're testing with Dart for the Web (such as with DartPad), you will not get microsecond precision due to limitations with JavaScript. Running the following code in the Dart VM will show a change in microseconds:
void main() {
var now = DateTime.now();
const microsecond = Duration(microseconds: 1);
print(now); // Prints: 2022-04-23 20:39:28.295803
print(now.add(microsecond)); // Prints: 2022-04-23 20:39:28.295804
}
Also see: https://stackoverflow.com/a/60747710/

Time with flutter

I am totally new with flutter and I do not understand how can I resolve a problem.
I'm actually working to a kart race app and:
I need to read a string like 1:02.456
Convert in some kind of time
Compare with another string similar to first one
Go to do something
es:
blap = null;
if(1:02.456 < 1:03.589){
blap = '1:02.456';
} else {
blap = '1:03.589;
}
I read on the web that I ca use the class DateTime, but every time I try to convert the string in an object of that class, I do not get wat I want.
There is a better way?
Thank you.
If you are working on a kart race app probably you need to use Duration, not DateTime.
This is one way to convert a string like yours into Duration
Duration parseDuration(String s) {
int hours = 0;
int minutes = 0;
int micros;
List<String> parts = s.split(':');
if (parts.length > 2) {
hours = int.parse(parts[parts.length - 3]);
}
if (parts.length > 1) {
minutes = int.parse(parts[parts.length - 2]);
}
micros = (double.parse(parts[parts.length - 1]) * 1000000).round();
return Duration(hours: hours, minutes: minutes, microseconds: micros);
}
Then, to compare two Duration in the way you wanted, this is an example:
String blap;
Duration time1=Duration(hours: 1),time2=Duration(hours: 2);
if(time1.compareTo(time2)<0){
//time2 is greater than time1
blap=time1.toString();
}else{
blap=time2.toString();
}

FusedLocationProviderClient stop giving locationResult after several LocationRequest

Please help if anybody has idea what happened with this case.
I have BroadcastReceiver which register to ForegroundService. This BroadcastReceiver will listen to Intent.ACTION_SCREEN_ON and called startLocationUpdates() if it receive any.
fun startLocationUpdates(context: Context, entity: LockEntityDB?) {
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context)
mSettingsClient = LocationServices.getSettingsClient(context)
mLocationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult?) {
super.onLocationResult(locationResult)
val location = locationResult?.lastLocation
locationResult?.let {
saveLocation(context, it.lastLocation)
locationUpdatesCount(context)
}
//something will do with entityDb
}
}
mOneTimeLocationRequest = LocationRequest().apply {
interval = 5 * 1000
fastestInterval = 1000
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
numUpdates = 1
}
val builder = LocationSettingsRequest.Builder()
builder.addLocationRequest(mOneTimeLocationRequest!!)
mLocationSettingsRequest = builder.build()
mSettingsClient
?.checkLocationSettings(mLocationSettingsRequest)
?.addOnSuccessListener {
mFusedLocationClient?.requestLocationUpdates(mOneTimeLocationRequest, mLocationCallback, null)
}
?.addOnFailureListener { e ->
kTimberLog(context, "loc " + e.toString())
}
}
So the idea if user turn on the phone, it will send Intent.ACTION_SCREEN_ON and FusedLocationProviderClient will update actual user location.
The problem is, when user try to turn on the phone after 5-6x FusedLocationProviderClient never give any locationResult anymore.
The more weirdest part all this locationResult for the 6th times and so on will start reappearing when user open the MainActivity.
Additional info : I m testing this code on 3 emulator : Nexus 5 API 23, PIXEL 3 API 29, Galaxy Nexus API 29. It works fine for Nexus 5 API 23.
Anybody know what is the reason of this behavior? Thank you very much
After struggling for few days, I found the solution here :
https://developer.android.com/training/location/request-updates#continue-user-initiated-action
After adding this line into my manifest, everything looks working fine
<service
android:name="MyBackgroundService"
android:foregroundServiceType="location" ... >
...
I hope can help somebody who are stuck in same problem

MongoDB shell : print results

If I execute ONLY the 1st part of the following short script in Robo3T, I get the results printed to the screen.
If I execute it with 2nd part, I only get the standard answer "Script executed successfully, but there are no results to show".
How can I print intermediate results such as those expected for 2nd part ?
I precise that concession & mission are both similar JSON objects.
I spent hours on this simple question. Please help.
var mission = db.mission.find({"googleCalendarEventId":"QiVJdbL"});
while (mission.hasNext()) {
var record = mission.next();
print(record.googleCalendarEventId + "," + record.concessionIdSet[0])
};
// 2nd part //
var concession = db.cursor.findOne({"_id": ObjectId(mission.concessionIdSet[0])});
while (concession.hasNext()) {
var record = concession.next();
print(record)
};
Thanks again #stennie, for others who would have the same issues, here's one code that worked for me and the 2 errors I committed :
1/ difference between find (--> cursor) and findOne (--> 1 element)
2/ actions in the loop had to be nested inside the loop --> I used a function and it works:
const missions = db.mission.find({
$and:[{"concessionToInvoice": {$exists: false}},
{"concessionIdSet":{$size:1}}]
});
missions.forEach((mission) => {
const concession = getConcession(mission);
print(mission.googleCalendarEventId+"- invoice to :"+concession.name);
mission.concessionToInvoice = getConcessionToInvoice(concession); //another function
db.mission.save(mission);
});
function getConcession(mission){
const concession = db.concession.findOne({"_id": ObjectId(mission.concessionIdSet[0])});
return concession;
}

how to calculate the time in the hr:min:sec

Can some one help me out from the time calculation in form of hr:min:sec. But I does need the system time. That's for I made this code
I try to make time calculation in the form of hr:min:sec
but it doesn't work in right way(it work till one hours)&
((1)after the 60 second output is 0:1:60 (2)after the 61 second output is 0:1:71 (3)after after the 3600 second output is 1:1:00 but(3)after the 3601 second output is wrong )
Here is the code:
In the .m file
-(IBAction)start
{
timer1 = [NSTimer scheduledTimerWithTimeInterval:(.01) target:self selector:#selector(timepassed) userInfo:nil repeats:YES];
}
-(void)timepassed
{
counter++;
if(sec==60)
sec=0;
else
sec=counter/100;
if(min==60)
min=0;
else
min=sec/60;
if(hr==24)
hr=0;
else
hr=min/60;
m1++;
NSString *l=[NSString stringWithFormat:#"%i:%i:%i",hr,min,sec];
[m setText:l];
}
-(void) timepassed
{
counter++;
if (counter == 60) { secs++; counter = 0; }
if (secs == 60) { min++; secs = 0; }
if (min == 60) { hr++; min = 0; }
// Your usual output here
}
Keep in mind that this sets the counter variable different than your code, i.e. it stores only 1/100 secs from 0...99.
There are of cause a dozen of algorithms to translate times into hrs:mins:secs, this is just one of them that's similar to your code.
Side note: Please accept answers that did help you (also on your older questions), this is common behavior on this site and keeps people motivated to help you.