kunzite (kunzite1) wrote in component_help,
kunzite
kunzite1
component_help

new clock component

based on this.
updated version of this.
hopefully solving this bug.
date formats.
example output.

var string k1Cheader       = "clock";
var int    k1Ctimezone     = 8;
var int    k1Ctimezone_min = 0;
var int    k1Ctz_neg       = 1;
var int    k1Cdst          = 0;

var string{} k1Cclock;
var int[]    k1Ctotal_month_days = [0, 31, 28, 31, 30, 31, 31, 30, 31, 30, 31, 30, 31];
var Page     k1Cp                = get_page();
var string   k1Cdate             = $k1Cp.time->date_format();
var string   k1Ctime             = $k1Cp.time->time_format();
var string   k1Cdayname          = $k1Cp.time->date_format("%%da%%");
var int      k1Cyear             = 0;
var int      k1Cmonth            = 0;
var int      k1Cday              = 0;
var int      k1Chour             = 0;
var int      k1Ctime_iso         = 0;
var int      k1Cmin              = 0;
var string   k1Cnegpos           = "+";
var bool     k1Cleap             = false;
var bool     k1Cprev_leap        = false;
if ($k1Ctz_neg == 1){
$k1Cnegpos = "-";
}
if ($k1Cdst == 1){
$k1Ctimezone = $k1Ctimezone + 01;
}
if ($k1Ctimezone < 00 or $k1Ctimezone > 12){
$k1Ctimezone = 00;
}
if ($k1Ctimezone_min >= 60 or $k1Ctimezone_min < 00){
$k1Ctimezone_min = 00;
}
$k1Cyear  = int(  $k1Cp.time->date_format("%%yyyy%%"));
$k1Cmonth = int(0+$k1Cp.time->date_format("%%mm%%"));
$k1Cday   = int(0+$k1Cp.time->date_format("%%dd%%"));
$k1Chour  = int(0+$k1Cp.time->date_format("%%HH%%"));
$k1Cmin   = int(0+$k1Cp.time->date_format("%%min%%"));

var int k1Ctz_year         = $k1Cyear;
var int k1Ctz_hour         = $k1Chour;
var int k1Ctz_min          = $k1Cmin;
var int k1Ctz_day          = $k1Cday;
var int k1Ctz_mon          = $k1Cmonth;
var int k1Cprev_month_days = 30;
var int k1Cfeb_days        = 28;
var int k1Cday_num         = 1;
var int k1Cmonth_days      = 31;
var int k1Cyear_days       = 365;
var int k1Cprev_year_days  = 365;
var int k1Cprev_year       = $k1Cyear - 1;

if ((($k1Cyear % 4 == 0) && ($k1Cyear % 100 != 0)) || ($k1Cyear % 400 == 0)){
  $k1Cleap      = true;
  $k1Cfeb_days  =  29;
  $k1Cyear_days = 366;
}

if ((($k1Cprev_year % 4 == 0) && ($k1Cprev_year % 100 != 0)) || ($k1Cprev_year % 400 == 0)){
  $k1Cprev_leap      = true;
  $k1Cprev_year_days = 366;
}

$k1Cmonth_days      = $k1Ctotal_month_days[$k1Cmonth];
$k1Cprev_month_days = ($k1Cmonth > 1) ? $k1Ctotal_month_days[$k1Cmonth - 1] : $k1Ctotal_month_days[12];

if ($k1Cmonth == 03){
  $k1Cprev_month_days = $k1Cfeb_days;
} else {
  if ($k1Cmonth == 02){
    $k1Cmonth_days = $k1Cfeb_days;
  }
}

if ($k1Ctz_neg == 1){
  $k1Ctz_hour = $k1Chour - $k1Ctimezone;
  $k1Ctz_min  = $k1Ctz_min - $k1Ctimezone_min;
} else {
  $k1Ctz_hour = $k1Chour + $k1Ctimezone;
  $k1Ctz_min  = $k1Ctz_min + $k1Ctimezone_min;
}

if ($k1Cdayname == $*lang_dayname_short[1]){
  $k1Cday_num = 1;
} else {
  if ($k1Cdayname == $*lang_dayname_short[2]){
    $k1Cday_num = 2;
  } else {
    if ($k1Cdayname == $*lang_dayname_short[3]){
      $k1Cday_num = 3;
    } else {
      if ($k1Cdayname == $*lang_dayname_short[4]){
        $k1Cday_num = 4;
      } else {
        if ($k1Cdayname == $*lang_dayname_short[5]){
          $k1Cday_num = 5;
        } else {
          if ($k1Cdayname == $*lang_dayname_short[6]){
            $k1Cday_num = 6;
          } else {
            if ($k1Cdayname == $*lang_dayname_short[7]){
              $k1Cday_num = 7;
            }
          }
        }
      }
    }
  }
}

if ($k1Ctz_min >= 60){
  $k1Ctz_min  = $k1Ctz_min  - 60;
  $k1Ctz_hour = $k1Ctz_hour +  1;
} else {
  if ($k1Ctz_min < 00){
    $k1Ctz_min  = $k1Ctz_min  + 60;
    $k1Ctz_hour = $k1Ctz_hour -  1;
  }
}


if ($k1Ctz_hour >= 24){
  $k1Ctz_hour = $k1Ctz_hour - 24;
  $k1Ctz_day  = $k1Ctz_day  +  1;
  $k1Cday_num = $k1Cday_num +  1;
} else {
  if ($k1Ctz_hour < 00){
    $k1Ctz_hour = $k1Ctz_hour + 24;
    $k1Ctz_day  = $k1Ctz_day  -  1;
    $k1Cday_num = $k1Cday_num -  1;
  }
}

if ($k1Ctz_day > $k1Cmonth_days){
  $k1Ctz_day = $k1Ctz_day - $k1Cmonth_days;
  $k1Ctz_mon = $k1Ctz_mon + 1;
}

if ($k1Ctz_day <= 00){
  $k1Ctz_day = $k1Ctz_day + $k1Cprev_month_days;
  $k1Ctz_mon = $k1Ctz_mon - 1;
}

if ($k1Ctz_mon > 12){
  $k1Ctz_mon  = $k1Ctz_mon  - 12;
  $k1Ctz_year = $k1Ctz_year +  1;
} else {
  if ($k1Ctz_mon <= 0){
    $k1Ctz_mon  = $k1Ctz_mon  + 12;
    $k1Ctz_year = $k1Ctz_year -  1;
  }
}

if ($k1Cday_num <= 0){
  $k1Cday_num = 7 + $k1Cday_num;
}

var string k1CAMPM = "PM";

if ($k1Ctz_hour >= 00 and $k1Ctz_hour < 12){
  $k1CAMPM = "AM";
}

var int k1Ctw_hour = $k1Ctz_hour;

if ($k1CAMPM == "PM"){
  $k1Ctw_hour = $k1Ctw_hour - 12;
}

if ($k1Ctw_hour == 0) {
  $k1Ctw_hour = 12;
}

var int k1Cyy_year = $k1Ctz_year - 1900;
if ($k1Cyy_year >= 100){
  $k1Cyy_year = $k1Cyy_year - 100;
}
var string k1Cday_ordinal = lang_ordinal($k1Ctz_day);

$k1Cdayname = $*lang_dayname_long[$k1Cday_num];
var string k1Cmonthname = $*lang_monthname_long[$k1Ctz_mon];

# date
$k1Cclock{"m"}           = string($k1Ctz_mon);
$k1Cclock{"mm"}          = zeropad($k1Cclock{"m"}, 2);
$k1Cclock{"d"}           = string($k1Ctz_day);
$k1Cclock{"dd"}          = zeropad($k1Cclock{"d"}, 2);
$k1Cclock{"yy"}          = string($k1Cyy_year);
$k1Cclock{"yyyy"}        = string($k1Ctz_year);
$k1Cclock{"mon"}         = $*lang_monthname_short[$k1Ctz_mon];
$k1Cclock{"month"}       = $k1Cmonthname;
$k1Cclock{"da"}          = $*lang_dayname_short[$k1Ctz_day];
$k1Cclock{"day"}         = $k1Cdayname;
$k1Cclock{"dayord"}      = $k1Cday_ordinal;
$k1Cclock{"date_long"}   = $k1Cclock{"day"} + ", " + $k1Cclock{"month"} + ", " + $k1Cclock{"dayord"} + ", " + $k1Cclock{"yyyy"};

# time
$k1Cclock{"H"}           = string($k1Ctz_hour);
$k1Cclock{"HH"}          = zeropad($k1Cclock{"H"}, 2);
$k1Cclock{"h"}           = string($k1Ctw_hour);
$k1Cclock{"hh"}          = zeropad($k1Cclock{"h"}, 2);
$k1Cclock{"min"}         = zeropad(string($k1Ctz_min), 2);
$k1Cclock{"A"}           = $k1CAMPM->substr(0, 1);
$k1Cclock{"a"}           = $k1Cclock{"A"}->lower();

# offset
$k1Cclock{"z"}           = string($k1Ctimezone);
$k1Cclock{"z_min"}       = string($k1Ctimezone_min);
$k1Cclock{"offset"}      = $k1Cnegpos + zeropad(string($k1Ctimezone), 2) + zeropad(string($k1Ctimezone_min), 2);

$k1Cclock{"time_short"}  = $k1Cclock{"h"} + ":" + $k1Cclock{"min"} + " " + $k1Cclock{"a"} + "m (" + $k1Cclock{"offset"} + " GMT)";

$k1Cclock{"datetime"}    = $k1Cclock{"date_long"} + " - " + $k1Cclock{"time_short"};

print_comp_header($k1Cheader);
print $k1Cclock{"datetime"};
print_comp_footer();
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 9 comments