Simple Time Zone conversion for WinRT, Windows Store and Windows Phone 8 apps
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.nuget
NuGet
PhoneAppWithTimeZones.Wp81Sl
PhoneAppWithTimeZones
TimeZones.NetCore
TimeZones.NetFx.Tests
TimeZones.NetFx
TimeZones.Tests.Shared
TimeZones.WP8.Native
TimeZones.WP8.Tests
TimeZones.WP8
TimeZones.WPA.Tests
TimeZones.WinRT.Shared
TimeZones.WinRT.Tests
TimeZones.WinRT
TimeZones.WinRT81
TimeZones.WinRTPcl.Tests
TimeZones
packages/FluentAssertions.Local
.gitattributes
.gitignore
LICENSE.txt
README.md
TimeZones.sln
TimeZones.sln.ARM.Debug.ForceImportBeforeCppTargets.props
TimeZones.sln.ARM.Release.ForceImportBeforeCppTargets.props
TimeZones.sln.DotSettings
TimeZones.sln.Mixed Platforms.Debug.ForceImportBeforeCppTargets.props
TimeZones.sln.Mixed Platforms.Release.ForceImportBeforeCppTargets.props
WinRTTimeZones.nuspec
build.proj
pack.cmd

README.md

WinRTTimeZones

Simple Time Zone conversion for WinRT, Windows Store, .NET and Windows Phone 8 apps.

PCL

WinRTTimeZones is implemented as a Portable Class Library that can be used at the above frameworks.

Installation

The easiest way to get started is to use the NuGet package. Make sure you have NuGet 2.1 installed first.

Install-Package WinRTTimeZones

Usage

There's a single entry point for use:

using TimeZones;	
public void ConvertTime()
{
	// Get the time zone we want

	var tz = TimeZoneService.FindSystemTimeZoneById("Central Standard Time");
	var dt = new DateTime(1990, 7, 1, 12, 0, 0, DateTimeKind.Utc);
	
	// This time will be central time
	var local = tz.ConvertTime(dt);
}

The main APIs are in the TimeZoneService class:

/// <summary>
/// All available time zone Id's
/// </summary>
public static IReadOnlyList<string> SystemTimeZoneIds

/// <summary>
/// All available time zones
/// </summary>
public static IReadOnlyList<ITimeZoneEx> AllTimeZones

/// <summary>
/// Gets a TimeZoneEx by id.
/// </summary>
/// <param name="id">Invariant Time Zone name. See SystemTimeZoneIds property for full list.</param>
/// <returns></returns>
public static ITimeZoneEx FindSystemTimeZoneById(string id)

/// <summary>
/// Converts a DateTimeOffset to one in the specified system time zone
/// </summary>
public static DateTimeOffset ConvertTimeBySystemTimeZoneId(DateTimeOffset dateTimeOffset, string destinationTimeZoneId)

/// <summary>
/// Sets the specified timezone on the date without converting the time
/// </summary>
public static DateTimeOffset SpecifyTimeZone(DateTimeOffset dateTimeOffset, ITimeZoneEx timeZone)

/// <summary>
/// UTC Time Zone
/// </summary>
public static ITimeZoneEx Utc

/// <summary>
/// Local Time Zone
/// </summary>
public static ITimeZoneEx Local

For repeated use, you can get a reference to a specific ITimeZoneEx instance:

/// <summary>
/// Represents a time zone
/// </summary>
public interface ITimeZoneEx
{
    /// <summary>
    /// Determines if the current datetime value is in daylight time or not
    /// </summary>
    bool IsDaylightSavingTime(DateTimeOffset dateTimeOffset);

    /// <summary>
    ///  Gets a DateTimeOffset for this time zone
    /// </summary>
    DateTimeOffset ConvertTime(DateTimeOffset dateTimeOffset);

    /// <summary>
    /// Normal offset from UTC
    /// </summary>
    TimeSpan BaseUtcOffset { get; }
    
    /// <summary>
    /// Localized name for standard time
    /// </summary>
    string StandardName
    {
        get;
    }
    
    /// <summary>
    /// Localized name for daylight time
    /// </summary>
    string DaylightName { get; }

    /// <summary>
    /// System Id for this time zone
    /// </summary>
    string Id { get; }
}

Tests

The project contains full unit tests.

Support

For questions or support, please contact @onovotny on Twitter.