Anyway, what this code allows you to do is basically let you set up a counter that will show you the days remaining until the date you inputed. kunzite tried to make it display hours and minutes as well, but no luck, but if we somehow manage it, I'll update the code. Without further a do, here it is:
# remove this line if you already have other custom components
function print_free_text (Page p){
########################################
# COUNTER CODE
# By: eduthepenguin
# Based on kunzite1's clock code, without whom this thing wouldn't even work. #
# Mad PROPS to him and xevinx
########################################
# USER SETTINGS
#
# set this to your time zone difference
var int e1time_difference = -3;
#
# set this to 1 if it is between spring and fall #
var int e1daylight_savings = 0;
#
# Insert the number of the day in which counter should reach 0 #
var int e1custom_day = 1;
#
# Insert the number of the month in which counter should reach 0 #
var int e1custom_month = 7;
#
# Insert the number of the year in which counter should reach 0 #
var int e1custom_year = 2004;
# Leave it in 1 if you want the counter to show up. If it's in 0 #
# the text you put in the "e1text" will appear #
var int e1enable = 1;
#
# Write here any text that you want to display, besides the counter. #
# You can use HTML on the text, but don't use inverted comma except the ones #
# at the beginning and the end of the text.
#
# This is the text that'll be displayed besides the counter #
var string e1misc_text = "Number of days!";
#
# Write here the message that will show up if "e1enable" is set on 0 #
var string e1text = "More kewl counters coming up!";
#
# Write here the title of the counter component(don't use HTML on this one). #
var string e1title = "Kewl Counters";
########################################
# COUNTER START #
#################
var int e1year = $p.time.year;
var int e1day = $p.time.day;
var int e1hour = $p.time.hour + $e1time_difference;
var int e1min = $p.time.min;
var int e1month = $p.time.month;
if($e1daylight_savings){
$e1hour = $e1hour + 1;
}
# figure out days in month
var int e1mondays = 31;
if($e1month == 4 or $e1month == 6 or $e1month == 9 or $e1month == 11) {
$e1mondays = 30;
} elseif($e1month == 2) {
if($e1year % 4 == 0){
$e1mondays = 29;
} else {
$e1mondays = 28;
}
}
var int e1febDays = $e1year % 4 == 0 ? 29 : 28; # number of days in february
var int e1isLeap = $e1year % 4 == 0 ? 1 : 0; # is this a leap yr?
var int[] monthDays = [0, 31, $e1febDays, 31, 30, 31, 30, 31, 31, 30, 31, 30,
31]; # array of days per month
if($e1hour > 24) { # if your timezone is the day after system...
$e1hour = $e1hour - 24; # figure out new hour value
$e1day = $e1day + 1; # make sure to change day value
if($e1day > $e1mondays) { # if your day is in the next month...
$e1day = $e1day - $e1mondays; # figure out the new day
$e1month = $e1month + 1; # change the month value
if($e1month > 12) { # if your month is in the next year...
$e1month = 1; # change the month value and
$e1year = $e1year + 1; # change the year value
}
}
} elseif($e1hour < 0) { # otherwise, if your day is the day before...
$e1hour = 24 + $e1hour; # change the hour and
$e1day = $e1day - 1; # change the day value
if($e1day < 1) { # if that puts you in the previous month...
$e1month = $e1month - 1; # decrement the month value
if($e1month < 1) { # if that puts you in the previous year...
$e1month = 12; # set the new month value and
$e1year = $e1year - 1; # decrement the year value
}
$e1mondays = 31; # figure out how many days are in this new month
if($e1month == 4 or $e1month == 6 or $e1month == 9 or $e1month == 11) {
$e1mondays = 30;
} elseif($e1month == 2) {
$e1mondays = ($e1year % 4) == 0 ? 29 : 28;
}
$e1day = $e1mondays; # and change your day value to that.
}
}
var int e1diff_year = $e1custom_year - $e1year; # difference in years
var int e1diff_day = $e1custom_day - $e1day; # difference in days
var int e1days = ((365 + $e1isLeap) * $e1diff_year); # convert years to days
foreach var int i ($e1month + 1 .. $e1custom_month){ # convert months to days
$e1days = $e1days + $monthDays[$i];
}
$e1days = $e1days + $e1diff_day; # add difference in days to days
print_comp_header($e1title); # decomment this line if this'll go in another component
if($e1enable == 1){
"""<b><font size = 2>$e1misc_text</b></font><p>""";
"""<b>$e1days Day/s</b>""";
} else {
"""<b>$e1text<b>""";
}
print_comp_footer(); # decomment this line if this'll go in another component
} # remove this character if you already have other custom components
###############
# COUNTER END #
###############