Skip to content

Instantly share code, notes, and snippets.

View mattjohnsonpint's full-sized avatar

Matt Johnson-Pint mattjohnsonpint

View GitHub Profile
@mattjohnsonpint
mattjohnsonpint / Program.cs
Created November 7, 2015 19:36
Demonstration for StackOverflow question 33579361
using System;
using System.Globalization;
using NodaTime;
using NodaTime.Text;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
@mattjohnsonpint
mattjohnsonpint / wordpresstz.html
Created October 12, 2015 20:02
Wordpress Timezone List
<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">
<optgroup label="Africa">
<option value="Africa/Abidjan">Abidjan</option>
<option value="Africa/Accra">Accra</option>
<option value="Africa/Addis_Ababa">Addis Ababa</option>
<option value="Africa/Algiers">Algiers</option>
<option value="Africa/Asmara">Asmara</option>
<option value="Africa/Bamako">Bamako</option>
<option value="Africa/Bangui">Bangui</option>
<option value="Africa/Banjul">Banjul</option>
@mattjohnsonpint
mattjohnsonpint / moment-timezone-detection.js
Last active October 5, 2015 16:02
WIP for guessing the current time zone using moment.js & moment-timezone
function guessTimeZone() {
// First try ECMA-402 time zone detection, unless true is passed for testing the rest of this function.
if (!arguments[0] && typeof Intl === "object" && typeof Intl.DateTimeFormat === "function") {
var tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
if (tz === "UTC") return "Etc/UTC";
if (tz && tz.indexOf('/') > -1) return tz;
}
// get the current timestamp - used throughout
@mattjohnsonpint
mattjohnsonpint / moment-tz-guess.md
Created September 29, 2015 22:55
Testing moment-timezone guess feature
Windows Display Name Windows ID Preferred Response Moment Guess Result January Offset July Offset Notes
(UTC-12:00) International Date Line West Dateline Standard Time Etc/GMT+12 Etc/GMT+12 Match -12:00 -12:00
(UTC-11:00) Coordinated Universal Time-11 UTC-11 Etc/GMT+11 Pacific/Pago_Pago Acceptable -11:00 -11:00
(UTC-10:00) Hawaii Hawaiian Standard Time Pacific/Honolulu Pacific/Honolulu Match -10:00 -10:00
(UTC-09:00) Alaska Alaskan Standard Time America/Anchorage America/Anchorage Match -09:00 -08:00
@mattjohnsonpint
mattjohnsonpint / DatePartFunctions.js
Last active June 25, 2017 00:45
JS replacement functions for timestamp <==> date parts without using the Date object
var d365 = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 ];
var d366 = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 ];
function parts2ts(year, month, day, hour, minute, second, millisecond) {
if (month < 0 || month > 11) {
return NaN;
}
var leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
var days = leap ? d366 : d365;
@mattjohnsonpint
mattjohnsonpint / 1-code.cs
Last active August 29, 2015 14:24
Testing MySql
using System;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
namespace TestMySql
{
class Program
{
static void Main(string[] args)
{
@mattjohnsonpint
mattjohnsonpint / Test.cs
Created July 4, 2015 00:30
xUnit / Json issue
using Newtonsoft.Json;
using Xunit;
using Xunit.Abstractions;
namespace XUnitJsonTest
{
public class Class1
{
private readonly ITestOutputHelper _output;
using System;
using System.Globalization;
using System.Threading;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
@mattjohnsonpint
mattjohnsonpint / Program.cs
Last active September 6, 2022 17:15
Airport Time Zones
using System.Text.RegularExpressions;
using GeoTimeZone; // Import from Nuget package "GeoTimeZone" (https://github.com/mattjohnsonpint/GeoTimeZone)
using TimeZoneConverter; // Import from Nuget package "TimeZoneConverter" (https://github.com/mattjohnsonpint/TimeZoneConverter)
namespace AirportTimeZones;
internal static class Program
{
private static void Main()
{
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
This shows how you can calculate the elapsed time in MSBuild
-->
<Target Name="BeforeBuild">
<PropertyGroup>
<startTime>$([System.DateTime]::UtcNow)</startTime>