Skip to content

Commit

Permalink
Relates to #7, attempt to reconcile TZ on init
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Tuttle committed May 14, 2015
1 parent 81ff1e7 commit 2f5f6fe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
4 changes: 3 additions & 1 deletion moment.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ component displayname="moment" {
this.zone = '';
this.time = '';
this.utcTime = '';
this.localTime = '';

/*
Call:
Expand All @@ -29,6 +30,7 @@ component displayname="moment" {
this.zone = zone;
this.utc_conversion_offset = getTargetOffsetDiff( getSystemTZ(), zone, time );
this.utcTime = TZtoUTC( arguments.time, arguments.zone );
this.localTime = UTCtoTZ( this.utcTime, getSystemTZ() );
return this;
}

Expand Down Expand Up @@ -134,7 +136,7 @@ component displayname="moment" {
mask = mask;
}

return dateTimeFormat( this.time, mask );
return dateTimeFormat( this.localTime, mask, this.zone );
}

public function from( required moment compare ) hint="returns fuzzy-date string e.g. 2 hours ago" {
Expand Down
45 changes: 31 additions & 14 deletions tests/testbox/tests.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -603,37 +603,54 @@ component extends="testbox.system.BaseSpec" {
var testZones = [
{
zone: 'Asia/Hong_Kong'
,short: 'CTT'
,short: 'HKT'
,shortDST: 'HKT'
}
,{
zone: 'America/Los_Angeles'
,short: 'PST'
,shortDST: 'PDT'
}
];

//these dates + times were chosen to have leading zeros in all applicable places, as well as being in and out of DST
//2009 DST was May 8 to Nov 1
var timeNoDST = '2009-03-05 09:03:07';
var timeDST = '2009-03-09 09:03:07';

for(var z in testZones){
var test = moment( timeNoDST, z.zone );
debug( test );
var testNoDST = moment( timeNoDST, z.zone );
var testDST = moment( timeDST, z.zone );
debug( testNoDST );
debug( testDST );

//basic date and time fields; these could easily pass through to dateTimeFormat
expect( test.format('yyyy') ).toBe( '2009' );
expect( test.format('yy') ).toBe( '09' );
expect( test.format('mmmm') ).toBe( 'March' );
expect( test.format('mmm') ).toBe( 'Mar' );
expect( test.format('mm') ).toBe( '03' );
expect( test.format('m') ).toBe( '3' );
expect( test.format('EEEE') ).toBe( 'Thursday' );
expect( test.format('EEE') ).toBe( 'Thu' );
expect( test.format('dd') ).toBe( '05' );
expect( test.format('d') ).toBe( '5' );
expect( testNoDST.format('yyyy') ).toBe( '2009' );
expect( testNoDST.format('yy') ).toBe( '09' );
expect( testNoDST.format('mmmm') ).toBe( 'March' );
expect( testNoDST.format('mmm') ).toBe( 'Mar' );
expect( testNoDST.format('mm') ).toBe( '03' );
expect( testNoDST.format('m') ).toBe( '3' );
expect( testNoDST.format('EEEE') ).toBe( 'Thursday' );
expect( testNoDST.format('EEE') ).toBe( 'Thu' );
expect( testNoDST.format('dd') ).toBe( '05' );
expect( testNoDST.format('d') ).toBe( '5' );

expect( testDST.format('yyyy') ).toBe( '2009' );
expect( testDST.format('yy') ).toBe( '09' );
expect( testDST.format('mmmm') ).toBe( 'March' );
expect( testDST.format('mmm') ).toBe( 'Mar' );
expect( testDST.format('mm') ).toBe( '03' );
expect( testDST.format('m') ).toBe( '3' );
expect( testDST.format('EEEE') ).toBe( 'Monday' );
expect( testDST.format('EEE') ).toBe( 'Mon' );
expect( testDST.format('dd') ).toBe( '09' );
expect( testDST.format('d') ).toBe( '9' );
//more to come here...

//now check formattings with time zones
expect( test.format('long') ).toBe( 'March 5, 2009 9:03:07 AM #z.short#' );
expect( testNoDST.format('long') ).toBe( 'March 5, 2009 9:03:07 AM #z.short#' );
expect( testDST.format('long') ).toBe( 'March 9, 2009 9:03:07 AM #z.shortDST#' );
}
});
it("works for custom masks", function(){
Expand Down

0 comments on commit 2f5f6fe

Please sign in to comment.