How to get the current time in UTC? - windows-runtime

I'm trying to get the current time in UTC in a UWP application. This should be a simple matter of constructing a DateTime object
DateTime const now{ clock::now() };
and accessing its UniversalTime field. However, that field does not appear to have been projected into C++/WinRT.
How do I get the current time in UTC using C++/WinRT?

Looks like a documentation bug. That field doesn't exist in C++/WinRT. Instead, DateTime is projected as a std::chrono::time_point. But similar to C++/CX, the documentation for the struct (not the field) is still somewhat accurat - it has the same granularity as FILETIME. But even easier than extracting the value youself, winrt::clock provides static methods to_file_time and to_time_t that convert DateTime to
FILETIME or time_t, respectively.
I'll get the documentation fixed up, and I've been meaning to write a blog post about how C++/WinRT seamlessly interops with std::chrono for timekeeping. I'm a a fan of std::chrono, and incorporating it into C++/WinRT was my idea, so the haters know who to blame. :)

Related

Caffeine - How to set for each entity its own "expiration time"

We used to use the guava cache and we want to change it to caffeine.
We want to set for each entity its own "expiration time", something like - put(K key, V value, long expiration_time).
I saw the 3 functions above and I wonder what exactly they are doing, if you can explain me the meaning ant the operations of each one of them it will be great.
For example, the return value of expireAfterCreate should be the duration we want for this entity from it's creation untill it's expiration? or something else?
I'm also wondering why we have the parameter "currentTime" in both expireAfterRead and expireAfterUpdate if we don't use it in the function?
When we used the guava cache we used the expireAfterAccess, what is the substitution for it in caffeine?
My last question is how can I set a default value for entities without a unique expiration time.
Thank you,
May
When we used the guava cache we used the expireAfterAccess, what is the substitution for it in caffeine?
We mirror the Guava API, so this is also available on the cache builder.
My last question is how can I set a default value for entities without a unique expiration time.
Use expireAfterAccess, expireAfterWrite, or return a constant duration with expireAfter(Expiry).
I saw the 3 functions above and I wonder what exactly they are doing, if you can explain me the meaning ant the operations of each one of them it will be great.
Expiry is a callback interface where a single timestamp value is updated. The invoked method corresponds to the operation performed on the cache entry (created, updated, read). An update or read that should have no effect can return currentDuration to no-op.
For example, the return value of expireAfterCreate should be the duration we want for this entity from it's creation untill it's expiration? or something else?
Yes. However if the expireAfterUpdate returns a custom value (something other than currentDuration), then that overrides the prior expiration duration.
I'm also wondering why we have the parameter "currentTime" in both expireAfterRead and expireAfterUpdate if we don't use it in the function?
This can most often be ignored, but is provided if somehow useful. It is the current nano timestamp from the Ticker (not wall clock time).
We want to set for each entity its own "expiration time", something like - put(K key, V value, long expiration_time).
The callback Expiry is required and generally recommended, because ideally entries are loaded through the cache to avoid stampedes (e.g. LoadingCache). A stampede is when multiple threads lookup the same entry, miss, load it, and overwrite each other putting it in. That wasted work rather than having only one thread perform the load and others wait for the results.
That said, this method is available under Cache.policy().expiresVariably(). Those configuration-specific methods are stashed in that area to offer more power when deemed necessary.
Thank you,
You're very welcome.

Custom `returnFormat` in ColdFusion 10 or 11?

I've a function which is called from different components, .cfms or remotely. It returns the results of a query.
Sometimes the response from this function is manually inspected - a person may want to see the ID of a specific record so they can use it elsewhere.
The provided return formats, being wddx, json, plain all aren't very easily readable for a layman.
I'd love to be able to create a new return format: dump, where the result first writeDumped and then returned to the caller.
I know there'd be more complicated ways of solving this, like writing a function dump, and calling that like a proxy by providing the component, function and parameters so it can call that function and return the results.
However I don't think it's worth going that far. I figured it'd be great if I could just write a new return format, because that's just... intuitive and nice, and I may also be able to use that technique to solve different problems or improve various workflows.
Is there a way to create custom function returnFormats in ColdFusion 10 or 11?
(From comments)
AFAIK, you cannot add a custom returntype to a cffunction, but take a look at OnCFCRequest. Might be able to use it to build something more generic that responds differently whenever a custom URL parameter is passed, ie url.returnformat=yourType. Same net effect as dumping and/or manipulating the result manually, just a little more automated.
From the comments, the return type of the function is query. That being the case, there is simply no need for a custom return format. If you want to dump the query results, do so.
queryVar = objectName.nameOfFunction(arguments);
writeDump (queryVar);

AS3 - Longest data types needed

I need a long data type. Using Number and Uint usually stops me at 4.2 billion. Any way I can have a really really long data type? And I need full integers, not decimals(API only accepts integers). I cannot find anything anywhere. Adobe says Number is extremely large (1.7*10E308) but at 4.2 bil, it always resets to 0...
Any idea?
Looks like this right now:
var gold:Number=0;
var highscoregold:uint=0;
highscoregold=gold;
gold_txt.text= ""+gold;
I don't believe there is native "big integer" type in Action Script and related libraries.
There are some external libraries that implement type (usually called BigInteger as Java counterpart) you are looking for. I.e. some random links found by searching for actionscript biginteger: As3 BigInteger returns an Incorrect Answer or http://www.granitedataservices.com/public/docs/2.3.2/docs/reference/en-US/html/graniteds.bignumbers.html

Checking if release date is newer than current date (Liquid/Html + Metafields)

I am trying to make a simple check in liquid (the language on shopify) using a metafield (a value manually assigned to each item).
If you are unfamiliar with liquid you can check on the shopify forums as it is very easy o understand and very similar to most current languages, but I can use plain html or css in it as well if it'd be easier.
The metafield.global.release_date for the item in question has a string value of "17-10-2013". I can assign any value I choose as the release date, either in string or integer format. (I can for instance even embed a video).
What I want is to check the metafield.global.release_date of an item is newer or older then the current date, then simply change the output text to be either "item is available for Pre-Order", or "item is In Stock"based on the result.
The text output is simple and I can do it myself, the problem comes in reading the metafield release date as it is just plain text that is input by me for each individual item, I cannot figure out how to convert it to a format that can be used to check against the current date.
If I had more experience in css/html or had knowledge of java I may have been able to figure it out myself, but with my limited knowledge this is unfortunately something I cannot do yet.
Please can someone provide some simple code, such as an if-statement that I could use, if you need more information please just ask.
Thanks.
-EDIT-
Basically this is what I need the code to do:
-Check metafield.global.release_date
-Check Current Date
-If metafield.global.release_date > Current date THEN "Game is Available for Pre-Order"
-Else "Game is In Stock"

Date Issue when migrating code from WCF to Web API

I'm working on a iOS application, that used to work using WCF.
We're changing this product to use MVC Web API instead of WCF.
I'm facing a problem with the dates! they must bebin JSON format such like
/Date(1373476260000-0600)/
But what is returned actually is of this format
/Date(1379484000000)/
which is not accepted by iOS controller and produces the default date value (like if it's null and it's just initializing it to the default value (12/31/1969))
I've tried to parse the date to the wanted JSON format date string, but it resulted in an exception because it's expecting a DateTime object instead.
I've also tried to add the following line:
GlobalConfiguration.Configuration.Formatters.JsonFormatter. SerializerSettings.DateParseHandling = Newtonsoft.Json.DateParseHandling.DateTimeOffset;
to the WebApiConfig.cs file but it's not working, then I've tried to add it to the AttributeRoutingHttpConfig.cs file then to the Global.asax but no response!
Then I've tried:
var appXmlType = GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
also added them to the 3 files mentioned above but it didn't work!
Any ideas how to solve this?
P.S: I only have access to the Web API code! I can't alter the iOS code!
Thanks.
First, be sure you have set:
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings
.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat;
Otherwise you will get the ISO8601 format instead of the Microsoft format. (ISO8601 is much better, but you said you can't change the iOS app.)
Then, you need to realize that for DateTime values, the .Kind has an effect on how the serialization works. If you have one with DateTimeKind.Utc, then it will not contain an offset because that's how this particular format works.
If you want to ensure that an offset is always produced, then use the DateTimeOffset value instead. This will provide an offset of +0000 for UTC.
For example:
var settings = new JsonSerializerSettings
{
DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
};
var dt = DateTimeOffset.UtcNow;
var json = JsonConvert.SerializeObject(dt, settings);
Debug.WriteLine(json); // "\/Date(1383153418477+0000)\/"
But you need to be very careful with this approach that all consumers honor the offset. For example, if a client receives this and parses it into a DateTime using WCF's DataContractJsonSerializer, there's a known bug that any offset will be treated as if it was the local time of the receiving computer, regardless of what the value of that offset actually is.
If at all possible, you should switch over both the server and the application to use ISO8601 formatting instead.
It seems the time zone portion of the date gets lost - try setting this in WebApiConfig:
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;