Javascript Tip: Datez

A quick one!

A coworker of mine had an interesting problem regarding cross-browser javascript dates.  

Does this look fine to you?

new Date('2016-08-29T14:42:07.56')

It looks fine to me.  It turns our it's not fine. In order for this code to return you an expected datetime across browsers (in our case Chrome and IE), we should specify either a timezone or a specific offset.  Since we didn't particularly care to add a specific offset, we used

new Date('2016-08-29T14:42:07.56Z')

Yep, we just slapped a "Z" on there.  Apparently, "Z" is a zero-time UTC offset (-00:00).  

This happens because Chrome assumes an unspecified date to be a UTC time with a zero-offset, while IE assumes the timezone should be the same timezone of the client machine (in our case, EST, -05:00).

If you wanted to specify your particular locale's offset, you could construct the date this way

new Date('2016-08-29T14:42:07.56Z-05:00')

Thanks to Moshe Karmel for the advice!  

For reasons like this, I tend to use momentjs for basically everything having to do with dates. 

Windows Authentication and Web API 2

I've recently had a situation come up at work where I need to protect our ASP.NET Web API 2 deployment with Windows Authentication.  We run our web client through Chrome and IE and we needed the NTLM negotiation to be handled gracefully.  There are a few things that we had to put in place to get this to go.  Here they are in list form.  The code for both the problem and the solution is here on my github.

Read More

Intro to SQL Part 1 - RDBMS and Retrieving Data

Intro to SQL Part 1 - RDBMS and Retrieving Data

A friend of mine asked me to do a tutorial on SQL, so here we go!  This article will begin to introduce relational database concepts and will end with a few examples of how to retrieve data from a database using the select keyword.  I'll stick to keeping this intro extremely basic - SQL heads please chime in with anything that might help someone just starting off in the world of databases.  We will be approaching this topic from the perspective of an application developer - not a Database Administrator.  Here's a TLDR for those who prefer to start at the end and work your way back to the beginning.

Read More

Revealing Module + Angular

Revealing Module + Angular

Recently, I've been getting deep into JavaScript.  It was my first programming language many years ago.  Since then, some extremely interesting patterns and practices have emerged.  As a primarily C# developer, I looked into the Revealing Module pattern as a way to ease myself back into JS coding in an OOP-friendly way.  

At work, I'm currently building a multi-module JS app with RESTful backend, using Google's AngularJS library for only one of the modules.  I was worried about how it would act when integrated with an app that also makes use of jQuery and Bootstrap.  As it turns out, it's totally fine!  This post is an overview of my approach to modularizing Angular functionality.

If you're the kind of person who likes to dig into the code before hearing the explanation, here's  a fiddle that contains everything I'll be talking about.

This post does assume some basic knowledge of how to set up an Angular app.  Instructions for that part can be found here on Angular's own tutorial.

Read More