Skip to content

Commit

Permalink
Item11506: TDD: Write tests for $we
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/branches/Release01x01@14085 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OlivierRaginel authored and OlivierRaginel committed Feb 24, 2012
1 parent 52982b3 commit 9e3818f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
5 changes: 3 additions & 2 deletions UnitTestContrib/test/unit/Fn_REVINFO.pm
Expand Up @@ -349,10 +349,11 @@ OFNIVER
my $y = $topicObject->expandMacros('%REVINFO{"$time"}%'); my $y = $topicObject->expandMacros('%REVINFO{"$time"}%');
$x = Foswiki::Time::formatTime( $t, $Foswiki::cfg{DefaultDateFormat} ); $x = Foswiki::Time::formatTime( $t, $Foswiki::cfg{DefaultDateFormat} );
$y = $topicObject->expandMacros('%REVINFO{"$date"}%'); $y = $topicObject->expandMacros('%REVINFO{"$date"}%');
$this->assert_str_equals( $x, $y );


foreach my $f ( foreach my $f (
qw(rcs http email iso longdate sec min hou day wday qw(rcs http email iso longdate sec min hou day wday
dow week mo ye epoch tz) dow week we mo ye epoch tz)
) )
{ {
my $tf = '$' . $f; my $tf = '$' . $f;
Expand All @@ -371,7 +372,7 @@ sub test_Item10476 {


my ($topicObject) = $this->_createHistory(); my ($topicObject) = $this->_createHistory();
my $format = my $format =
'sec=$sec, seconds=$seconds, min=$min, minutes=$minutes, hou=$hou, hours=$hours, day=$day, wday=$wday, dow=$dow, week=$week, month=$month, mo=$mo, ye=$ye, year=$year, ye=$ye, tz=$tz, iso=$iso, isotz=$isotz, rcs=$rcs, http=$http, epoch=$epoch, longdate=$longdate'; 'sec=$sec, seconds=$seconds, min=$min, minutes=$minutes, hou=$hou, hours=$hours, day=$day, wday=$wday, dow=$dow, week=$week, we=$we, month=$month, mo=$mo, ye=$ye, year=$year, ye=$ye, tz=$tz, iso=$iso, isotz=$isotz, rcs=$rcs, http=$http, epoch=$epoch, longdate=$longdate';


my $ui = $topicObject->expandMacros( '%REVINFO{"' . $format . '"}%' ); my $ui = $topicObject->expandMacros( '%REVINFO{"' . $format . '"}%' );


Expand Down
44 changes: 42 additions & 2 deletions UnitTestContrib/test/unit/TimeTests.pm
Expand Up @@ -340,16 +340,56 @@ sub test_week {
$this->assert_equals( 1, $week ); $this->assert_equals( 1, $week );
} }


sub test_we {
my $this = shift;

# 2004 started on a thursday, so 1st Jan is in week 1
my $time = Time::Local::timegm( 1, 0, 0, 1, 0, 104 );
my $week = Foswiki::Time::formatTime( $time, '$we', 'gmtime' );
$this->assert_str_equals( '01', $week );

# 4th was the sunday of the first week, so also week 1
$time = Time::Local::timegm( 1, 0, 0, 4, 0, 104 );
$week = Foswiki::Time::formatTime( $time, '$we', 'gmtime' );
$this->assert_str_equals( '01', $week );

# 5th was monday of second week, so week 2
$time = Time::Local::timegm( 1, 0, 0, 5, 0, 104 );
$week = Foswiki::Time::formatTime( $time, '$we', 'gmtime' );
$this->assert_str_equals( '02', $week );

# poke back into 2003; 31st is in week 1 of 2004
$time = Time::Local::timegm( 1, 0, 0, 31, 11, 103 );
$week = Foswiki::Time::formatTime( $time, '$we', 'gmtime' );
$this->assert_str_equals( '01', $week );

# and 28th in week 52
$time = Time::Local::timegm( 1, 0, 0, 28, 11, 103 );
$week = Foswiki::Time::formatTime( $time, '$we', 'gmtime' );
$this->assert_str_equals( 52, $week );

# 1999 started on a friday, so 1st is week 53 of 1998
# (week 0 of 1999)
$time = Time::Local::timegm( 1, 0, 0, 1, 0, 99 );
$week = Foswiki::Time::formatTime( $time, '$we', 'gmtime' );
$this->assert_str_equals( 53, $week );

# And 4th is week 1
$time = Time::Local::timegm( 1, 0, 0, 4, 0, 99 );
$week = Foswiki::Time::formatTime( $time, '$we', 'gmtime' );
$this->assert_str_equals( '01', $week );
}

sub test_parseTimeFormatString { sub test_parseTimeFormatString {
my $this = shift; my $this = shift;


my $format = my $format =
'sec=$sec, seconds=$seconds, min=$min, minutes=$minutes, hou=$hou, hours=$hours, day=$day, wday=$wday, dow=$dow, week=$week, month=$month, mo=$mo, ye=$ye, year=$year, ye=$ye, tz=$tz, iso=$iso, isotz=$isotz, rcs=$rcs, http=$http, epoch=$epoch, longdate=$longdate'; 'sec=$sec, seconds=$seconds, min=$min, minutes=$minutes, hou=$hou, hours=$hours, day=$day, wday=$wday, dow=$dow, week=$week, we=$we, month=$month, mo=$mo, ye=$ye, year=$year, ye=$ye, tz=$tz, iso=$iso, isotz=$isotz, rcs=$rcs, http=$http, epoch=$epoch, longdate=$longdate';


my $time = Time::Local::timegm( 1, 0, 0, 1, 0, 104 ); my $time = Time::Local::timegm( 1, 0, 0, 1, 0, 104 );
my $formatted = Foswiki::Time::formatTime( $time, $format ); my $formatted = Foswiki::Time::formatTime( $time, $format );
my $expected = my $expected =
'sec=01, seconds=01, min=00, minutes=00, hou=00, hours=00, day=01, wday=Thu, dow=4, week=1, month=Jan, mo=01, ye=04, year=2004, ye=04, tz=GMT, iso=2004-01-01T00:00:01Z, isotz=Z, rcs=2004/01/01 00:00:01, http=Thu, 01 Jan 2004 00:00:01 GMT, epoch=1072915201, longdate=01 Jan 2004 - 00:00'; 'sec=01, seconds=01, min=00, minutes=00, hou=00, hours=00, day=01, wday=Thu, dow=4, week=1, we=01, month=Jan, mo=01, ye=04, year=2004, ye=04, tz=GMT, iso=2004-01-01T00:00:01Z, isotz=Z, rcs=2004/01/01 00:00:01, http=Thu, 01 Jan 2004 00:00:01 GMT, epoch=1072915201, longdate=01 Jan 2004 - 00:00';


$this->assert_equals( $expected, $formatted ); $this->assert_equals( $expected, $formatted );
} }
Expand Down

0 comments on commit 9e3818f

Please sign in to comment.