My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
BasicUsage  
Basic usage of haxealtdate
Featured
Updated Feb 4, 2010 by damonsb...@gmail.com

Introduction

The haxealtdate package provides support for JulianDays, and Gregorian (normal calendar) support for dates outside haxe.Date, which of course is limited to the normal 1970-2038 of the timestamp. As well, there is a fairly complete implementation of 'zic', the timezone compiler, which will allow for creating Gregorian dates like so:

var mydate = new altdate.Gregorian();
mydate.set(true,new tz.zones.america.New_York(),2007,06,28,12,30);
trace(altdate.Tools.format(g,"%F %T %Z"));

Will output 2007-07-28 12:30:00 EDT

Since the Gregorian dates store internally as Julian, math on them is simple.

mydate.value = mydate.value + 1; /// adds one day.

Changing the timezone will be just as simple

mydate.timezone = new tz.zones.Japan(); // which is an alias for tz.zones.asia.Tokyo
trace(altdate.Tools.format(g,"%F %T %Z"));

Creating dates that don't exist results in overflow so

mydate.set(true,new tz.zones.america.New_York(),2007,0,32,12,30);

Results in February 1, 2007

The year, month, day hours, minutes,seonds fields of Gregorian dates can be assigned, including overflow.

mydate.month=13; // February, next year.
mydate.hour -= 1;
mydate.month += 1; // careful, if day was 31, and next month only goes to 30, overflows to 1st of month after next

Compiling

On platforms with no EReg support, ie. Flash 7 and Flash 8, define NO_EREG using the haXe compiler switch -D NO_EREG

Warnings

Size

With Timezone support, yhe entire package is over 1.5MB of data, when compiled in Neko. This does not mean you cannot use the haxealtdate package, just avoid using the class tz/Timezone.hx, which loads all data for all zones. You can selectively use individual timezones in your applications by instancing only the timezones you actually require.

POSIX and GMT

Some bright cookie decided that the abbreviation for dates East of the meridian should be referred to as minus. This means UTC+2 is equivalent to GMT-2. Not sure why... still trying to figure that out. So if you are 2 hours East of London, use GMT-2, New York would be GMT+5. Regardless, there is little reason to use the GMT offset rules, since almost every location on the planet is now in the timezone database.

Leap Seconds

Bah! Who needs 'em anyway? ;) Not implemented yet.

PACKAGE altdate

PACKAGE tz

All of the files in /tz are compiled from /tzparser. Do not modify them!

  • Timezone
  • every other timezone is tz.zones.location

PACKAGE tzparser

This package includes the raw timezone data and compiler used to create everything in the tz package. It is not documented, but the supplied build.hxml will create Parser.n that can recreate /tz from /tzparser/data. Is not included in the lite zip files.


Sign in to add a comment
Powered by Google Project Hosting