C++ TeeChart X-Axis apply time as value that increase - c++builder

I recieve temperature from a climateboard.
This values I put for y-axis for every second:
if(GetTickCount()-start_time>=1000)
{
start_time = GetTickCount();
DlgMainWindow->ChartTemperatureCurve->Series[0]->AddY(ConnectionThread->CurrentTemperature/10.0, "", clBlue);
}
The X-Axis protocols the time. It works for every second. But it doesn´t look very fine, cause after a minute i get 61 seconds and so on.
Is there a possibility to change the value of x-Axis? When i try to change the properties and change to ge DateTime, i recieve date but not the time.
Formats to hh:mm:ss changes the y-value but not the x-value like i need.
And can i get the time, i start the measurement?
So if I start with 11:51:10 --> this would be the Start-Value and every measurement value would continue --> 11:51:11 and so on.

it was so simple and I didn´t recognize it:
if(GetTickCount()-start_time>=1000)
{
AnsiString DateAndTime = FormatDateTime("hh:nn:ss", Now());
start_time = GetTickCount();
DlgMainWindow->ChartTemperatureCurve->Series[0]->AddY(ConnectionThread->CurrentTemperature/10.0, DateAndTime, clBlue);
}

Related

How To Calculate Time Left For The Day

I have used formula "=TEXT( NOW() , "HH:mm" )" for the current time of the day.
What formula can I use to calculate the time that is left till the end of the day, 12am?
Say the current time now is 7:12pm. I would like to have a formula that would be able to calculate that I only have 4:48 hours left till 12am.
Try =TEXT(1 - NOW()), "HH:mm").
Use TIMEVALUE
https://support.google.com/docs/answer/3267350
Which returns the fraction of a day that a time represents. So you can chain it with NOW.
=TIMEVALUE(NOW())
Would return 0.5 if it was midday.
So then you can
= 1 - TIMEVALUE(NOW())
To get the amount of time left in the day expressed as a fraction.
Then you wrap it in your TEXT function to get it in hours and minutes.
=TEXT(1-TIMEVALUE(NOW()), "HH:ss")

How to More Elegantly Calculate Epoch Time for Next Sunday at Midnight in Dart?

When a user opens my app, there's a countdown timer that shows how much time left until Sunday at midnight (which is when the week's contest would end).
To get the initial value used in the countdown, my code adds 604800000 (which is the amount of milliseconds in a week) in a loop to a starting value of 1595203200000 (which the milliseconds since epoch of an arbitrary past Sunday at midnight) until it's greater than now:
int now = DateTime.now().millisecondsSinceEpoch;
int nextSundayAtMidnight = 1595203200000; // starting value is from arbitrary past Sunday at midnight
while (now > nextSundayAtMidnight) {
print('now is still greater than nextSundayAtMidnight so adding another 604800000 until it\'s not');
nextSundayAtMidnight += 604800000;
}
print('nextSundayAtMidnight is $nextSundayAtMidnight');
It works, but it seems like there should be a better way that's based on DateTime.now without having to manually specify that arbitrary starting value. Is there?
What's the syntax in dart to do this more elegantly?
Thanks in advance!
The following code uses addition of the difference in weekdays to get the date of the upcoming Sunday and then shifts the exact DateTime to being at 11:59:59 pm. There are comments in the code that describe what each line does.
It uses the many helpful methods already provided in the DateTime class in dart.
void main()
{
var now = DateTime.now();
//Obtains a time on the date of next sunday
var nextSunday = now.add(Duration(days: DateTime.sunday - now.weekday));
//Shifts the time to being 11:59:59 pm on that sunday
var nextSundayMidnight = DateTime(nextSunday.year, nextSunday.month, nextSunday.day + 1).subtract(Duration(seconds: 1));
//Gets the difference in the time of sunday at midnight and now
var timeToSundayMidnight = nextSundayMidnight.difference(now);
print(timeToSundayMidnight);
}

Calculate elapsed time using NOW() with conditional formatting

I'm trying to set up a Google Sheet for volunteers at the local dog shelter. The idea is to have an auto-updating spreadsheet that shows at a glance which dogs really need to be walked, in two ways:
conditional formatting the rows with color based on time elapsed:
red if it's been >6 hours since their last walk,
yellow for 3-6 hours, or
green if they were walked <3 hrs ago.
auto-sorting the rows so that the dogs that have gone the longest are always at the top of the list, and when they get walked, they go to the bottom of the list.
Here's where I'm at.
Problem 1: I'm trying to calculate time elapsed by using the NOW() function (which returns the current date and time), minus the time of the last walk. The problem is that if you only enter a time, Google apparently assumes the date is 12/30/1899. So if I put in 8:00 am, and the current time based on NOW() is 4:00 pm, instead of returning 8:00 hours, it calculates the the duration as 10,000,000+ hours that have elapsed since 8:00 am on December 30, 1899 up to the current date and time. (Similar problem discussed here).
If I keep the output cells in the HH:MM format, it'll initially look OK, because it'll just return the HH:MM as 8:00, BUT I can't use that because then the conditional formatting won't work - it's still actually calculating the 10,000,000 hours since 1899. So I can't set duration values for red/green/yellow because all the output values will be slowly increasing every day we get further away from 1899, meaning I would have to reset the ranges daily.
Obviously I could work around this by always including the time and date, but the idea is to have a spreadsheet that is idiot-proof so that any volunteer can use it by just adding the time they walked the dog. It won't work if they have to input the date too.
Problem 2: Assuming I can get the above to work, how can I set it up so the table automatically sorts itself after any change (i.e. when a dog gets walked and the entry gets updated)?
Help?
Please try:
Problem 1
Green is easy, just format all your data that way with standard fill (CF will override this where applicable).
Select A1 and apply a Custom formula is of:
=and($D1<>"",timevalue(now())>$D1+6/24)
with colour Red and Range A:E
Repeat (the order of these two is important):
=and($D1<>"",timevalue(now())>$D1+3/24)
with colour Yellow and Range A:E.
Save rules and close window.
Problem 2
Create a pivot table by selecting ColumnA:E (may have to get rid of some content present low down in the sheet first) and Data > Pivot Table Report..., to Rows Add field Dog name (do not Show totals), to Values Add field Time since last walk and Summarise by:SUM. Name the sheet PT.
In say J2 of your other sheet (not PT) enter:
=query(PT!A:B, "Select * order by B desc ")
May be worth noting that without the day part there might be problems where times span midnight - if you have walkers with insomnia?!
For the autosorting, I found a script elsewhere on stackoverflow and modified it slightly for my purposes:
function onEdit(event){
var sheet = SpreadsheetApp.getActiveSheet();
if(sheet.getName()=='Sheet1'){
var editedCell = sheet.getActiveCell();
var columnToSortBy = 4;
var tableRange = "a2:f91";
if(editedCell.getColumn() == columnToSortBy){
var range = sheet.getRange(tableRange);
range.sort( { column : columnToSortBy, ascending: true } );
}
}
}

joda overlap method for ambiguous hour

I'm trying to find out if there is any overlap between two joda intervals. value of the variables are given below. I'm not sure why the overlap is being returned as 'null'.
final Interval overlap = range.overlap(new Interval(beginDateTime, endDateTime));
beginDateTime = 2013-11-03T00:07:00.000Z
endDateTime = 2013-11-03T00:08:00.000Z
range = 2013-11-03T00:00:00.000-05:00/2013-11-03T23:59:59.999-06:00
Interval created by 'beginDateTime' and 'endDateTime' corresponds to ambiguous hour in America/Chicago time zone. Variable 'range' represents November 3rd in America/Chicago time zone.
I tried to debug into Interval.class, could not find out the reason.
thanks.
Never mind, found the issue.
beginDateTime and endDateTime be 2013-11-03T07:00:00.000Z and 2013-11-03T08:00:00.000Z respectively.
My test data was incorrect as listed in the question (that is not ambiguous hour, it is interval of just 1 minute, I swapped minutes with hour values) :)

annotated time line

I'm working with google annotated time line graphs: http://code.google.com/apis/visualization/documentation/gallery/annotatedtimeline.html
My question is: I would like to limit the X-axis to show just a range of hours between 5:00 and 21:00. Today I'm showing already per hour but I would like to limit the range and not show 24 hours. Is it possible?
Can't you just set the zoomStartTime and zoomEndTime to configure the part of the x axis that is shown?
Something like the following might do it, ie set the start and end date/times and also turn off the range and zoom functions.
annotatedtimeline.draw(data, {
'displayRangeSelector' : false,
'displayZoomButtons': false,
'zoomStartTime': new Date(2009, 1 ,2),
'zoomEndTime': new Date(2009, 1 ,5)});
Just a thought after looking here.

Resources