Zune Local Time-Zone Wrong using XNA

Besides the leap-year issue that recently caused Zune 30 devices to freeze on New Year’s Eve, it appears that another clock-related issue affects all Zune devices. When developing an XNA application with Game Studio 3.0 for the Microsoft Zune, querying the DateTime.Now and TimeZone.CurrentTimeZone properties seems to always return the local time and time-zone for Pacific Standard Time, irrespective of the actual time-zone for which the device is configured.

You can configure your correct local time through the Zune's Settings | Clock | Set Time menu, which the device can then display on the system menus outside of an XNA application. Inside your XNA application you can also get the correct Greenwich Mean Time when queried through DateTime.UtcNow – so the device appears to know what the actual correct local time-zone is, since it gets GMT/UTC right along with the menu clock. However, despite knowing the correct time-different between UTC and the “Set Time” value for the actual local time-zone, the Zune nonetheless gets DateTime.Now wrong in the XNA environment. Instead of the real local values, we always get “Pacific Standard Time” for the time-zone, and the DateTime.Now value is right for PST but is not the local time if you live in any other time-zone (that is not the North-American West-coast, where the Microsoft headquarters in Redmond happens to be located).

Existing clock/watch applications for the Zune (for example, Zune Clock 1.5 by Adrian Vinca, zClock 1.0 by Nelson the zune-ologist, and the ZuneBoards Clock by G. Andrew Duthie) seem to all mention time-zone or time-offset configuration that is needed, but the fundamental problem has not been discussed much. After all, the MSDN documentation does state that the DateTime.Now property specifies “the current date and time on this computer, expressed as the local time” and “a DateTime whose value is the current local date and time”, so no custom offset or time-zone manipulation should need to be performed by XNA applications. A thread about this topic on the highly active XNA Community Forums went unnoticed, and an XNA Framework bug report at Microsoft Connect was quickly closed (likely by Microsoft’s XNA Team) as an “external” issue and forwarded to the Zune Team for investigation. Hopefully there was someone to actually receive the forwarded report, since Microsoft also split the Zune Team recently – perhaps the new software-half of the team would look into the issue, or would this functionality have to wait for the Zune service and XNA on Windows Mobile? Getting the .NET Compact Framework to work consistently on all handheld devices, including the Zune, seems to be a challenge even for Microsoft.

If you live in a non-west-coast time-zone and would like to verify this issue on your Zune, I am including the source code and a binary package of a test application in ZIP and ccgame format, which can be deployed using Visual Studio and XNA Game Studio. The main part of the XNA application’s C# code is also listed below. Currently, the Zune device reports “Microsoft Windows CE 5.0.0” and “3.5.8220.0” for the OS and CLR version, respectively.

using System;
using System.Globalization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace TiaanDotCom.Samples.Zune.TimeZoneTest
{
public class MainGame : Microsoft.Xna.Framework.Game
{
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
private SpriteFont spriteFont;
private Vector2 textPosition;

public MainGame()
{
this.graphics = new GraphicsDeviceManager(this);
this.Content.RootDirectory = "Content";
this.TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0);
}

protected override void LoadContent()
{
this.spriteBatch = new SpriteBatch(this.GraphicsDevice);
this.spriteFont =
this.Content.Load<SpriteFont>("KootenaySize11");
}

protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).
Buttons.Back == ButtonState.Pressed)
{
this.Exit();
}
base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
this.GraphicsDevice.Clear(Color.White);
this.spriteBatch.Begin();
this.textPosition = Vector2.Zero;
DrawText("OS: " + Environment.OSVersion.ToString());
DrawText("CLR: " + Environment.Version);
DrawText("UTC: " + DateTime.UtcNow);
DrawText("Now: " + DateTime.Now);
DrawText("Zone: " + TimeZone.CurrentTimeZone.StandardName);
DrawText("Region: " + RegionInfo.CurrentRegion.EnglishName);
this.spriteBatch.End();
}

protected void DrawText(string text)
{
this.spriteBatch.DrawString(this.spriteFont, text,
this.textPosition, Color.Black);
this.textPosition.Y += this.spriteFont.MeasureString(text).Y;
}
}
}

Downloads:

Comments

Hello, Yes, when I wrote

Hello,

Yes, when I wrote zClock prior to the Zune including it's own Clock functionality I just thought it weird that it did not configure the correct time zone, I assume it was a firmware defect.

However, for it to work with unmanaged code yet be seemingly hard coded in it's managed counterpart is really weird.

You're right though, the time zone settings in zClock were just a bandaid on this problem which I hope is fixed in a subsequent release of the XNA Framework.

Regards,
Nelson

2 Years

It's been two years and the problem persists. I don't think Microsoft cares...

Re: 2 Years

Not surprisingly, the Zune has been discontinued. The following statement on Microsoft’s Zune Player Support and Service page appears to be only a few weeks old: “We recently announced that, going forward, Windows Phone will be the focus of our mobile music and video strategy, and that we will no longer be producing Zune players.”