Set cxDateEdit Time - delphi

Is there a way to set cxDateEdit's time to 0.00.00 ? Now,it always fetches the current time.
I want the time to 00. Thought I do not need time, even if I remove it, my date still takes time into the account.

You can turn off the display of the time by setting the Properties in the Object inspector. More specifically, Expand the Properties property and set Kind = ckDate

This seems to work:
DateUtils.DateOf(cxDateEdit1.Date);
The DateOf function as described in the reference:
Strips the time portion from a TDateTime value. Call DateOf to convert
a TDateTime value to a TDateTime value that includes only the date
information (sets the time portion to 0, which means midnight).

Related

How do I store the time part of NSDateComponents?

I want to store times type value (but not the date) in Core Data. Which data type should I use?
Possible options:
Three integer attributes for hour, minutes, seconds.
One string attribute for "HH:MM:SS".
One integer attribute for the number of seconds since midnight.
The best representation depends on what type of queries involving the time you want to
execute. The first option is better if you want to search for a given hour, minute or second. The other options are better if you have to search for time intervals.
My approach would probably be to convert it to an HHMMSS format, either as an integer or a string. NSDate isn't appropriate because it is stored as a interval since an epoch (seconds since 1970)
The date portion of an NSDate is inherently part of time. NSDate is a NSTimeInterval number of seconds positive or negative since the reference date. With a locale and a timezone you can get an appropriate localized display string on the fly.
In most cases it makes far more sense to store the number behind the NSDate returned by timeIntervalSinceReferenceDate
It's small and portable and correct.
Then recreate an NSDate with dateWithTimeIntervalSinceReferenceDate:
Then use an NSDateFormatter with NSLocale and NSTimeZone to get an appropriate value for display to users.
It's an unwieldy and cumbersome set of tools that actually help you do it right.
The good news is all the effort you expend in doing this pays off in making it easier next time and giving you code that will do the right thing and have a backing value that is actually really easy to store and manipulate.
Additionally by using the API correctly you will lose no precision and have more possibilities open to you.
Trying to do it with format strings alone seems easy and simple but is the road to bad code.

Check isDaylightSavingTime for

The Using Time Zones Guide
shows how to check if daylight saving time (DST) is in action for the current date and how to get the next date when daylight saving time changes. With calls to:
isDaylightSavingTime
daylightSavingTimeOffset
nextDaylightSavingTime
E.g.
Bool isDST = [[NSTimeZone systemTimeZone] isDaylightSavingTime];
But I need to find out if a future date is DST or not so that when users scroll to a distant and far off date, they can see my graph plotted with the time axis labelled correctly (GMT or BST).
The problem is that isDayLightSavingTime seems to take two parameters, one passed to it explicitly (NSTimeZone) and the other implicitly, namely the current system time.
You just need to call isDaylightSavingTimeForDate, passing in the relevant NSDate.
It's not that isDaylightSavingTime itself has two parameters - it's that it calls isDaylightSavingTimeForDate with the current date. From the docs for isDaylightSavingTime:
This method invokes isDaylightSavingTimeForDate: with the current date as the argument.
So just skip the "convenience" method and call isDaylightSavingTimeForDate specifying the date you want to check. (I'd give some sample code, but the chances of me getting Objective C syntax correct are very slim...)

TDateTimePicker with Kind=dtkDate returning time fraction in Date property?

I have a TDateTimePicker with Kind=dtkDate on my form.
When the form opens I do
TDateTimePicker.date := Date
I have a var lStartDay : TDateTime; and do
lStartDay := DatePickerStart.Date;
I have not touched the TDateTimePicker in the user interface.
Now, the evaluate/modify (Ctrl-F7) dialog and the watch list (and the cursor hovering over the code) show DatePickerStart.Date as 8-1-2014, but StartDate is 8-1-2014 15:00:00
When I edit the watch value DatePickerStart.Date to not use the visualizer it shows 41647,625 (it took me some time to find that!)
Why does TDateTimePicker.Date contain a time fraction?
Answering my own question to prevent others from tumbling into the same pit:
It turns out that when you place a TDateTimePicker on your form, the Time property gets filled with the current time and this always gets returned as part of DatePickerStart.Date. Mine was obviously placed on the form at 15:00:00
The time remains 'in' even when you use the TDateTimePicker so select another date.
So, to fix this: Clear the Time property at design time (it becomes 00:00:00) and/or always use Trunc(TDateTimePicker.Date) or DateOf(TDateTimePicker.Date) when you really only need the date.
Of itself, TDateTimePicker.Date does not return the date!.

timeZone in checkin

Looking at the docs there is a descrepancy between the data in a checkin object for the query API s the push API with regards to timeZone.
According to https://developer.foursquare.com/overview/realtime a sample push will contain the name of the tz eg America/New_York
However according to https://developer.foursquare.com/docs/responses/checkin (and the API explorer) a checkin object will contain the timeZone offset eg 60 for GMT+1
I havn't managed to confirm whats in the Push API myself yet as I hav to setup the SSL certs, can anyone confirm of the docs are correct and we do indeed have 2 type of tz format. I would have thought that including the timeZone rather than the offset would be better as this doesn't vary with Daylight Savings unlike the figure. Europe/London will always be a constant where as the offset will switch between 0 and 60 mins
I'm not directly familiar with FourSquare's API, so I can't confirm or deny this for you. But I can tell you there are often cases where you would use both.
It is ok to only present an offset, if the data represents a particular time. Since the checkin response provides a createdAt date/time as an integer seconds since epoch (aka a "Unix Timestamp"), then it is appropriate to provide a separate offset. (Although I find it interesting that they provide the offset as a string and not as an integer number of minutes.) The other way you might do this would be with a single DateTimeOffset values, usually presented in ISO8601 format, as in 2013-06-02T01:23:45-07:00. Either are acceptable.
But as you may be aware, an offset does not uniquely identify a time zone. In the case of a single event, it doesn't need to. But if it were a recurring event, or if there was a possibility that you might want to modify the time value, then an offset alone would not suffice. That's when you need the full zone identifier.
If you have a zone identifier such as America/New_York, then you can always find out what the correct offset for any date/time would be. But not everyone has a TZDB implementation readily available. For example, in .Net on Windows, you get Microsoft's clumsy time zone database by default, and you have to find a library (like NodaTime) if you want to use the TZDB zones.
It does seem strange that the push and pull for the same type of action (a check-in) would have different values just because they were going through different APIs. My advice (to Foursquare) would be threefold:
Be consistent about the data for the same activity, regardless of push vs pull.
Provide both the TZDB identifier, and the the UTC offset associated with the event.
Provide the event's timestamp and offset in a single value, as an ISO8601 formatted string, rather than a unix time integer.
The Foursquare documentation is correct but a bit incomplete (as of time of posting). The check-in response contains a timeZoneOffset field. The real-time push response has a timeZone field and a timeZoneOffset field—the timeZone field is still there for legacy purposes.
Thanks for pointing this out; we'll update the docs to reflect that timeZoneOffset is the preferred method at this point. As Matt mentioned, the offset method is a better way to identify a particular time from createdAt.

How to get the timezone name from numeric timezone value in Android

I am basically trying to read a .vcs file in Android. It has timezone value in the below format:
TZ:+05:30
Now I want to get the timezone name corresponding to this value. Means in this case it would be Kolkata(India).
Is there any code to achieve this in android?
TimeZone tz = TimeZone.getTimeZone("GMT-06:00");
String tzarr[] = TimeZone.getAvailableIDs(tz.getRawOffset());
for(int i=0;i<tzarr.length;i++)
(I'm assuming you can parse the text into an offset easily enough.)
In general, you can't. Something like "+05:30" just represents an offset from UTC at one particular time. It doesn't express how the offset changes within the time zone across the year (or across history). For example, for some of the time the Europe/London time zone has the same offset as Africa/Casablanca - but not always.
Assuming this is associated with a specific date/time, you could use TimeZone.getAvailableIDs, iterate over all the time zones, check what the offset from UTC is at that particular instant (using TimeZone.getOffset(long)) and see which time zones have the right offset at the right time. There could be many such zones though.
If you don't have a specific date/time, it's even more ambiguous. You can use getRawOffset and getDSTSavings to see whether the target offset is either the standard or DST offset for any particular zone - although note that these calls assume that for a particular time zone, the DST offset and standard offset remain the same across history (which isn't always true).

Resources