JavaScript, Date and ISO 8601 part3

As there seems some confusion and issues with JavaScript dates (here and here) I wanted to have a look at google Chrome and its ES6 capabilities. So I opened the javascript-harmony setting, enabled it and restarted chrome. I opened up the developer tools and hacked some ES6: Running it on Chrome 55.0.2883.87 m: Meh! The web is broken and nobody cares… So far, so good, so what?

JavaScript, Date and ISO 8601 part2

I had a JavaScript date issue some time ago. Today I looked at the sources of ChakraCore and dug to the point of interest. // Compute the time value timeValue = TvFromDate(year, month, day, timePortionMilliseconds - utcOffsetMilliseconds); if (isLocalTime) { // Compatibility note: // In ES5, it was unspecified how to handle date strings without the trailing time zone offset "Z|(+|-)HH:mm". // In ES5.1, an absent time zone offset defaulted to "Z", which contradicted ISO8601:2004(E). // This was corrected in an ES5.1 errata note. Moreover, the ES6 draft now follows ISO8601. timeValue = GetTvUtc(timeValue, scriptContext); } DateImplementation.cpp line 990   Let's have a look at the ISO8601:2004. B.1.3 Date and time of dayCombinations of calendar date and local time Basic format Extended format Explanation 19850412T101530 1985-04-12T10:15:30 Complete Let's have a look at the EcmaScript 2015 spec at Date Time String Format (20.3.1.16) If the time zone offset is absent, the date-time is interpreted as a local time. So as long as I'm running ES5.X Internet Explorer and Edge are wrong according to the EcmaScript spec. Which can be considered wrong according to the ISO spec and is corrected for ES6. <sarcasm>What a wonderful place the web is</sarcasm> I can understand somehow that Microsoft is not fixing this as it is for the old spec. So the next task is to see how the other browsers behave when forced to run ES6

If time is an issue, the lack of reading might be the root cause

Look at the following code:var x = new Date('2016-01-29T14:00:00'); console.log(x.getTime()); Running it in different browsers is surprising1454076000000 // Chrome | FF | Opera 1454072400000 // IE | Edge MDN says: The getTime() method returns the numeric value corresponding to the time for the specified date according to universal time. I repeat according to universal time! ECMA Script Spec says: Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC Pretty accurate. Let's change the code slightly by appending a Z at the end of the string being parsed as date: var x = new Date('2016-01-29T14:00:00Z'); console.log(x.getTime()); Here are the results:1454076000000 // Chrome | FF | Opera 1454076000000 // IE | Edge So it's definitely NOT the getTime() part that lacks. ECMA Script Spec says: The String may be interpreted as a local time, a UTC time, or a time in some other time zone, depending on the contents of the String. The function first attempts to parse the format of the String according to the rules called out in Date Time String Format (15.9.1.15). If the String does not conform to that format the function may fall back to any implementation-specific heuristics or implementation-specific date formats. Where the Date Time String Format (15.9.1.15) says The value of an absent time zone offset is “Z”. I repeat Z, which is universal time! If only the IE/Edge team was able to read and understand the specs... HTH, Daniel

Updating the .NET target framework for many projects

I do component based development. Meaning I have 30+ repos, builds and each of them has 1-10 projects – The main library project, tests, samples and so on. The news about the support end for the .NET Framework 4, 4.5 and 4.5.1 was the motivation to update ALL of my projects. I know this is not neccessary because… .NET 4.5.2, 4.6 and 4.6.1 are compatible, in-place updates on top of .NET 4, .NET 4.5, and .NET 4.5.1. This means that applications built to target any of these previous .NET 4.x versions will continue running on .NET 4.5.2 without change. No recompiling of apps is necessary. ... but I wanted to update them from version 4 to since a long time now. To do the job I wrote a small powershell script. Beside the path command set-frameworkVersion there is CommitAndPush-GitRepositories which commits and pushes all repositories found underneath the path variable.

Maven Archetypes in IntelliJ

IntelliJ has the ability to use Maven as build and project system. The concept of an archetype is a predefined project or project template.When “File | New project” is used to create a new project and “Maven” is selected the following dialog is displayed:IntelliJ comes with a few archetypes but of course custom ones can be added. On the MVN Repository for example several archetypes for Wildfly are available: http://mvnrepository.com/artifact/org.wildfly.archetypeThe XML snipped can be used as copy-paste-source for IntelliJ’s “Add archetype dialog”:After clicking the “OK” button the newly added archetypes are available as a source for the project creation. The custom archetypes are stored in the file “C:\{username}\Daniel\.IntelliJIdea{version}\system\Maven\Indices\UserArchetypes.xml” on Windows and “~/.IntelliJIdea{version}/system/Maven/Indices/UserArchetypes.xml” on Linux. Next define group and artifact identifier as well as version for the new project:Select the Maven version:And the project location:The result is a runnable quick start for working with the Wildfly application server.

Code Snippets in IntelliJ

Code snippets can be helpful. Otherwise the can lead to code duplicates – so use them with wisely.In JetBrains IntelliJ the code snipptes are called Live Templates. They are stored in files saved in C:\Users\{UserName}\.IntelliJIdea{Version}\config\templates on Windows and ~/.IntelliJIdea{Version}/config/templates on Linux. To create a live template open IntelliJ and open the Settings from the File menu:In the Settings dialog you can use the search text box to quickly access the Live Templates section:Now just select the Language and use the green plus button on the upper right to add a new one (like the iife that I just added here).There is a special placeholders that can be used aside from variables:$SELECTION$The Edit variables button switches to enabled state as soon as you user a variable name in the code.

Enable or disable FxCop Code Analysis solution wide in Visual Studio Package Manager Console

I really like FxCop. But in a debugging session it can be useful to save time by temporarily disabling the code analysis. Sadly there is no *global switch* to turn it off and on again. So here is my approach: Create a new text file in the directory "C:\Users\{your user}\Documents\WindowsPowerShell" named "NuGet_profile.ps1" and add the following code: Restart Visual Studio. Click the menu "View" | "Other Windows" | "Package Manager Console". Now you can execute the following commands: > Enable-CodeAnalysis > Disable-CodeAnalysis

.NET Licensing - ode to monolithic applications?

The Microsoft .NET Framework has a built in licensing technology. It can be found in the namespace System.ComponentModel and System.ComponentModel.Design. Here is a small sample implementation of the minimal required classes: A lot of component producers use this licensing model – so does Tx Text Control – the component that I wanted to use. As a user you just create a *.licx-file, include it into the project as “embedded resource” and add the components that should be licensed by their fully qualified type names – one per line: During the build the LC-Task executes the license compiler (LC.exe). The license compiler is part of the .NET SDK that is part of the Windows SDK. If you have the Windows SDK 8.1 or Visual Studio 2013 installed it can be found at “C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\”. The result is the “Licensing.dll.licenses” file that is embedded by the C#-Compiler (Csc.exe) in the next step. During runtime the LicenseProvider-attribute is evaluated and the defined license provider is handed over to the System.ComponentModel.LicenseManager’s Validate method. This call forwards to the internal method ValidateInternalRecursive which then calls the GetLicense method of the LicenseProvider. The first argument of the GetLicenseCall is of type LicenseContext and at runtime filled with the static held instance of the internal class RuntimeLicenseContext. To resolve the license key the method GetSavedLicenseKey is called on the LicenseContext. The implemention offers two options to resolve the key: Resolve from URI: new Uri(new Uri(AppDomain.CurrentDomain.SetupInformation.ApplicationBase), AppDomain.CurrentDomain.SetupInformation.LicenseFile) Resolve from Embedded Resource: The lookup on references/loaded assemblies is only processed, if there is NO entry assembly - for instance within ASP.NET that is the case. But my intend was to create a build task for MsBuild that converts Microsoft Word’s DOCX files into PDF documents. So I have an entry assembly (MsBuild.exe). The entry assembly knows nothing about TX TextControl – and that is a good thing! I have no control over the entry assembly (MsBuild.exe). A situation I guess to find in every composite UI/modular desktop application. No wonder the monolith is often the preferred architecture especially on the desktop! After an intense debugging session through the framework sources (supported by red gate’s Reflector) I wrote a small helper class. WARNING: I use reflection to access internal types and private fields and modify their values – this means: If Microsoft decides to change their internal implementation it might not work anymore. But as we as can see the code was written for .NET 1.0 and has not been updated in the last 10 years: It’s not very likely that changes will happen. Now I just need to call LicenseLoader.LoadLicensesFromCallingAssembly() before the Tx Text Control component is instantiated the first time and everything works as expected. HTH

Batch processing Visual Studio ProjectItems with the Nuget Package Management Powershell Console

Today I helped a customer to minify and bundle a bunch of JavaScript files. We used WebGrease triggered from MsBuild to do the job. The next thing to do is changing the BuildAction property on all non-bundled-and-minified JavaScript files so that only minified and bundled files are published. Here is my script: Hope that helps