Smart Dates
1.0 SP1.3
This mod smart formats dates.
- Admins have the option to show "Today" and the time, or just the time on today's events.
- "Yesterday" is shown on yesterday's events.
- Years are only shown for prior years, not the present one.
- Replaces the six time formats with six clearer ones.
The net effect is to cut down the output to a minimum, making it much clearer and easier to read on already over-crowded pages.
After applying the mod, visit the Preferences page to choose your "show today" setting - on or off.
The smart date formatting option can be over-ridden by hard coding. This is done, for example, for the time at the top of every page, because it's pointless showing the date if it's replaced by "Today". In calls to &timeformat(), add a second parameter with a value of 1 to turn off all the "today", "yesterday" and year-hiding formatting. i.e.
$showdate = &timeformat($showdate, 1);
Richard Carr
http://www.badpoo.co.uk/ronnie/pages/yabbmods.shtml
english.lng
1;
$smart_dates{'1'} = "Yesterday";
$smart_dates{'2'} = "Show \"Today\" before times when appropriate (or just time)?";
$txt{'480'} = "01/31/01 $txt{'107'} 13:15:17";
$txt{'481'} = "31.01.01 $txt{'107'} 13:15:17";
$txt{'482'} = "31.01.2001 $txt{'107'} 13:15:17";
$txt{'483'} = "Jan 12th, 2001, 1:15pm";
$txt{'484'} = "01/31/01 $txt{'107'} 1:15pm";
$txt{'485'} = "31. Jan $txt{'107'} 13:15";
$txt{'480'} = "31st Jan 2001 $txt{'107'} 1:15pm";
$txt{'481'} = "31st Jan 2001 $txt{'107'} 13:15";
$txt{'482'} = "31/01/01 $txt{'107'} 13:15";
$txt{'483'} = "1:15pm $txt{'30'} 31st Jan 2001";
$txt{'484'} = "13:15 $txt{'30'} 31/01/01";
$txt{'485'} = "01/31/01 $txt{'107'} 13:15";
Sources/Subs.pl
sub timeformat {
if ($settings[17] > 0) { $mytimeselected = $settings[17]; } else { $mytimeselected = $timeselected; }
$oldformat = $_[0];
if( $oldformat eq '' || $oldformat eq "\n" ) { return $oldformat; }
$oldmonth = substr($oldformat,0,2);
$oldday = substr($oldformat,3,2);
$oldyear = ("20".substr($oldformat,6,2)) - 1900;
$oldhour = substr($oldformat,-8,2);
$oldminute = substr($oldformat,-5,2);
$oldsecond = substr($oldformat,-2,2);
if ($oldformat ne '') {
use Time::Local 'timelocal';
eval { $oldtime = timelocal($oldsecond,$oldminute,$oldhour,$oldday,$oldmonth-1,$oldyear); };
if ($@) { return ($oldformat); }
my ($newsecond,$newminute,$newhour,$newday,$newmonth,$newyear,$newweekday,$newyearday,$newisdst) = localtime($oldtime + (3600 * $settings[18]));
$newmonth++;
$newweekday++;
$newyear += 1900;
$newshortyear = substr($newyear,2,2);
if ($newmonth < 10) { $newmonth = "0$newmonth"; }
if ($newday < 10 && $mytimeselected != 4) { $newday = "0$newday"; }
if ($newhour < 10) { $newhour = "0$newhour" };
if ($newminute < 10) { $newminute = "0$newminute"; }
if ($newsecond < 10) { $newsecond = "0$newsecond"; }
$newtime = $newhour.":".$newminute.":".$newsecond;
$usertimeoffset = $timeoffset + $settings[18];
($secx,$minx,$hourx,$dd,$mm,$yy,$tmpx,$tmpx,$tmpx) = localtime(time + (3600*$usertimeoffset));
$mm = $mm + 1;
$yy = ($yy % 100);
$dontusetoday = $_[1] + 0;
if ($mytimeselected == 1) {
$newformat = qq~$newmonth/$newday/$newshortyear $txt{'107'} $newtime~;
if ($mm == $newmonth && $dd == $newday && $yy == $newshortyear && $dontusetoday == 0) { $newformat = qq~$txt{'769'} $txt{'107'} $newtime~; }
return $newformat;
} elsif ($mytimeselected == 2) {
$newformat = qq~$newday.$newmonth.$newshortyear $txt{'107'} $newtime~;
if ($mm == $newmonth && $dd == $newday && $yy == $newshortyear && $dontusetoday == 0) { $newformat = qq~$txt{'769'} $txt{'107'} $newtime~; }
return $newformat;
} elsif ($mytimeselected == 3) {
$newformat = qq~$newday.$newmonth.$newyear $txt{'107'} $newtime~;
if ($mm == $newmonth && $dd == $newday && $yy == $newshortyear && $dontusetoday == 0) { $newformat = qq~$txt{'769'} $txt{'107'} $newtime~; }
return $newformat;
} elsif ($mytimeselected == 4) {
$newmonth--;
$ampm = $newhour > 11 ? 'pm' : 'am';
$newhour2 = $newhour % 12 || 12;
$newmonth2 = $months[$newmonth];
if( $newday > 10 && $newday < 20 ) { $newday2 = 'th '; }
elsif( $newday % 10 == 1 ) { $newday2 = 'st '; }
elsif( $newday % 10 == 2 ) { $newday2 = 'nd '; }
elsif( $newday % 10 == 3 ) { $newday2 = 'rd '; }
else{ $newday2 = 'th '; }
$newformat = qq~$newmonth2 $newday$newday2, $newyear, $newhour2:$newminute$ampm~;
if ($mm == $newmonth + 1 && $dd == $newday && $yy == $newshortyear && $dontusetoday == 0) { $newformat = qq~$txt{'769'} $txt{'107'} $newhour2:$newminute$ampm~; }
return $newformat;
} elsif ($mytimeselected == 5) {
$ampm = $newhour > 11 ? 'pm' : 'am';
$newhour2 = $newhour % 12 || 12;
$newformat = qq~$newmonth/$newday/$newshortyear $txt{'107'} $newhour2:$newminute$ampm~;
if ($mm == $newmonth && $dd == $newday && $yy == $newshortyear && $dontusetoday == 0) { $newformat = qq~$txt{'769'} $txt{'107'} $newhour2:$newminute$ampm~; }
return $newformat;
} elsif ($mytimeselected == 6) {
$newmonth2 = $months[$newmonth-1];
$newformat = qq~$newday. $newmonth2 $newyear $txt{'107'} $newhour:$newminute~;
if ($mm == $newmonth && $dd == $newday && $yy == $newshortyear && $dontusetoday == 0) { $newformat = qq~$txt{'769'} $txt{'107'} $newhour:$newminute~; }
return $newformat;
}
} else { return ''; }
}
#SMART DATES MOD START
#completely replaced timeformat
sub timeformat
{
if ($settings[17] > 0) { $mytimeselected = $settings[17]; }
else { $mytimeselected = $timeselected; }
$no_smart_dates = $_[1] || 0;
$oldformat = $_[0];
if( $oldformat eq '' || $oldformat eq "\n" ) { return $oldformat; }
$oldmonth = substr($oldformat,0,2);
$oldday = substr($oldformat,3,2);
$oldyears = substr($oldformat,6,2);
$oldyear = ("20".substr($oldformat,6,2)) - 1900;
$oldhour = substr($oldformat,-8,2);
$oldminute = substr($oldformat,-5,2);
$oldsecond = substr($oldformat,-2,2);
#get today
($todaydate, $junk, $junk) = split(/ /, $date);
($todaymonth, $todayday, $todayyear) = split(/\//, $todaydate);
#get yesterday
($yestsec,$yestmin,$yesthour,$yestmday,$yestmon,$yestyear,$yestwday,$yestyday,$yestisdst) = localtime( (time + (3600*$timeoffset)) - (86400) );
$yestmon++;
$yestmday = "0$yestmday" if ($yestmday < 10);
$yestmon = "0$yestmon" if ($yestmon < 10);
$yestsaveyear = ($yestyear % 100); $yestsaveyear = "0$yestsaveyear" if ($yestsaveyear < 10);
#is it today or yesterday?
$itistoday = ($todaymonth eq $oldmonth && $todayday eq $oldday && $todayyear eq $oldyears) ? 1 : 0;
$itwasyesterday = ($yestmon eq $oldmonth && $yestmday eq $oldday && $yestsaveyear eq $oldyears) ? 1 : 0;
#start output
if ($oldformat ne '')
{
use Time::Local 'timelocal';
eval { $oldtime = timelocal($oldsecond,$oldminute,$oldhour,$oldday,$oldmonth-1,$oldyear); };
if ($@) { return ($oldformat); }
my ($newsecond,$newminute,$newhour,$newday,$newmonth,$newyear,$newweekday,$newyearday,$newisdst) = localtime($oldtime + (3600 * $settings[18]));
$newmonth++;
$newweekday++;
$newyear += 1900;
$newshortyear = substr($newyear,2,2);
if ($newmonth < 10) { $newmonth = "0$newmonth" };
if ($newday < 10 && $mytimeselected != 4) { $newday = "0$newday" };
if ($newhour < 10) { $newhour = "0$newhour" };
if ($newminute < 10) { $newminute = "0$newminute" };
if ($newsecond < 10) { $newsecond = "0$newsecond" };
$newtime = $newhour.":".$newminute.":".$newsecond;
@month_names = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
#formatting options
if ($mytimeselected == 1)
{
$suffix = ''; $temp = $newday;
if( $temp > 10 && $temp < 20 ) { $suffix = 'th'; }
elsif( $temp % 10 == 1 ) { $suffix = 'st'; }
elsif( $temp % 10 == 2 ) { $suffix = 'nd'; }
elsif( $temp % 10 == 3 ) { $suffix = 'rd'; }
else{ $suffix = 'th'; }
if ($newday < 10) { $newday =~ s/^0//; }
$ampm = $newhour > 11 ? 'pm' : 'am';
$newhour2 = $newhour % 12 || 12;
$monthname = $month_names[$newmonth - 1];
if ($oldyears != $todayyear || $no_smart_dates) { $display_year = $oldyear += 1900; $display_year = ' ' . $display_year; } else { $display_year = ''; }
my $date_display = '';
if ($itistoday && !$no_smart_dates) { $date_display = ($smart_date_today) ? qq~$txt{'769'} $txt{'107'} ~ : ''; }
elsif ($itwasyesterday && !$no_smart_dates) { $date_display = qq~$smart_dates{'1'} $txt{'107'} ~; }
else { $date_display = qq~$newday$suffix $monthname$display_year $txt{'107'} ~; }
$newformat = qq~$date_display$newhour2\:$newminute$ampm~;
return $newformat;
}
elsif ($mytimeselected == 2)
{
$suffix = ''; $temp = $newday;
if( $temp > 10 && $temp < 20 ) { $suffix = 'th'; }
elsif( $temp % 10 == 1 ) { $suffix = 'st'; }
elsif( $temp % 10 == 2 ) { $suffix = 'nd'; }
elsif( $temp % 10 == 3 ) { $suffix = 'rd'; }
else{ $suffix = 'th'; }
if ($newday < 10) { $newday =~ s/^0//; }
$monthname = $month_names[$newmonth - 1];
if ($oldyears != $todayyear || $no_smart_dates) { $display_year = $oldyear += 1900; $display_year = ' ' . $display_year; } else { $display_year = ''; }
my $date_display = '';
if ($itistoday && !$no_smart_dates) { $date_display = ($smart_date_today) ? qq~$txt{'769'} $txt{'107'} ~ : ''; }
elsif ($itwasyesterday && !$no_smart_dates) { $date_display = qq~$smart_dates{'1'} $txt{'107'} ~; }
else { $date_display = qq~$newday$suffix $monthname$display_year $txt{'107'} ~; }
$newformat = qq~$date_display$newhour\:$newminute~;
return $newformat;
}
elsif ($mytimeselected == 3)
{
my $date_display = '';
if ($oldyears != $todayyear || $no_smart_dates) { $display_year = '/' . substr($oldyear, 1, 2); } else { $display_year = ''; }
if ($itistoday && !$no_smart_dates) { $date_display = ($smart_date_today) ? qq~$txt{'769'} $txt{'107'} ~ : ''; }
elsif ($itwasyesterday && !$no_smart_dates) { $date_display = qq~$smart_dates{'1'} $txt{'107'} ~; }
else { $date_display = qq~$newday/$newmonth$display_year $txt{'107'} ~; }
$newformat = qq~$date_display$newhour\:$newminute~;
return $newformat;
}
elsif ($mytimeselected == 4)
{
$suffix = ''; $temp = $newday;
if( $temp > 10 && $temp < 20 ) { $suffix = 'th'; }
elsif( $temp % 10 == 1 ) { $suffix = 'st'; }
elsif( $temp % 10 == 2 ) { $suffix = 'nd'; }
elsif( $temp % 10 == 3 ) { $suffix = 'rd'; }
else{ $suffix = 'th'; }
if ($newday < 10) { $newday =~ s/^0//; }
$ampm = $newhour > 11 ? 'pm' : 'am';
$newhour2 = $newhour % 12 || 12;
$monthname = $month_names[$newmonth - 1];
if ($oldyears != $todayyear || $no_smart_dates) { $display_year = $oldyear += 1900; $display_year = ' ' . $display_year; } else { $display_year = ''; }
my $date_display = '';
if ($itistoday && !$no_smart_dates) { $date_display = ($smart_date_today) ? qq~ $txt{'769'}~ : ''; }
elsif ($itwasyesterday && !$no_smart_dates) { $date_display = qq~ $smart_dates{'1'}~; }
else { $date_display = qq~ $txt{'30'} $newday$suffix $monthname$display_year~; }
$newformat = qq~$newhour2\:$newminute$ampm$date_display~;
return $newformat;
}
elsif ($mytimeselected == 5)
{
my $date_display = '';
if ($oldyears != $todayyear || $no_smart_dates) { $display_year = '/' . substr($oldyear, 1, 2); } else { $display_year = ''; }
if ($itistoday && !$no_smart_dates) { $date_display = ($smart_date_today) ? qq~ $txt{'769'}~ : ''; }
elsif ($itwasyesterday && !$no_smart_dates) { $date_display = qq~ $smart_dates{'1'}~; }
else { $date_display = qq~ $txt{'30'} $newday/$newmonth$display_year~; }
$newformat = qq~$newhour:$newminute$date_display~;
return $newformat;
}
elsif ($mytimeselected == 6)
{
my $date_display = '';
if ($oldyears != $todayyear || $no_smart_dates) { $display_year = '/' . substr($oldyear, 1, 2); } else { $display_year = ''; }
if ($itistoday && !$no_smart_dates) { $date_display = ($smart_date_today) ? qq~$txt{'769'} $txt{'107'} ~ : ''; }
elsif ($itwasyesterday && !$no_smart_dates) { $date_display = qq~$smart_dates{'1'} $txt{'107'} ~; }
else { $date_display = qq~$newmonth/$newday$display_year $txt{'107'} ~; }
$newformat = qq~$date_display$newhour:$newminute~;
return $newformat;
}
}
else { return ''; }
}
#SMART DATES MOD END
Sources/AdminEdit.pl
if ($showyabbcbutt) { $syabbcchecked = "checked" }
if ($allowpics) { $allowpicschecked = "checked" }
if ($smart_date_today) { $smart_date_today_checked = ' checked';}
$txt{'371'}
$smart_dates{'2'}
$maintenancetext = $FORM{'maintenancetext'} || "";
&ToHTML($maintenancetext);
$smart_date_today = $FORM{'smart_date_today'} || 0;
\$timeselected = $timeselected; # Select your preferred output Format of Time and Date
\$smart_date_today = $smart_date_today; # Show "Today" before times when appropriate (or just time)?
$txt{'480'}
$txt{'484'}
$txt{'483'}
$txt{'481'}
$txt{'482'}
$txt{'485'}
$txt{'480'}
$txt{'481'}
$txt{'482'}
$txt{'483'}
$txt{'484'}
$txt{'485'}
Sources/Profile.pl
$txt{'480'}
$txt{'484'}
$txt{'483'}
$txt{'481'}
$txt{'482'}
$txt{'485'}
$txt{'480'}
$txt{'481'}
$txt{'482'}
$txt{'483'}
$txt{'484'}
$txt{'485'}