There was a style of formatting dates in the USSR, which can now be found, perhaps, only on tombstones (that’s where the road goes). First the first two digits of the year, then the fraction by number / Roman month, then the second two digits of the year.

alt text

Task: as readable as possible and cross-browser format the date specified in Unix-format. Should work on standard libraries. The amount of code does not care, very concerned about matches, I mean, the speed of work.

My version. I do not like that the width of the number of days is not tracked. Hence the imperfect alignment:

function rus1960($time){ $year = date('Y',$time); $month = rome(date('n',$time)); $day = date('j',$time); $year = str_split($year,2); $day = '<span style="font-size: 0.5em; text-decoration: underline; vertical-align: top">'.$day.'</span>'; $month = '<span style="font-size: 0.5em; margin-left: -1.1em;">'.$month.'</span>'; return $year[0].$day.$month.$year[1]; } function rome($N){ $c='IVXLCDM'; for($a=5,$b=$s='';$N;$b++,$a^=7) for($o=$N%$a,$N=$N/$a^0;$o--;$s=$c[$o>2?$b+$N-($N&=-2)+$o=1:$b].$s); return $s; } 

PS At the same time present a new tag

  • Interestingly, google doesn't know such a word. - andrybak
  • one
    What word? Schillometry? =) Well, I will not write on the decent forum "f ** ometry", right? Skill - skill, skill - knes

2 answers 2

 <? $rome = array('', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII'); $year = date('Y'); $month = (int) date('n'); $day = date('j'); ?> <span style="line-height:200%"> <?=$year[0].$year[1]?> <span style="display:inline-block;text-align:center;line-height:100%;vertical-align:middle"> <div style="text-decoration:underline"><?=$day?></div> <?=$rome[$month]?> </span> <?=$year[2].$year[3]?> </span> 

No unnecessary function calls and calculations. CSS format as you need.

  • As for the Roman months - 10 points. =) And in HTML confuses Inline-block. IE has problems with it, doesn't it? - knes
  • In relation to span'am there are no problems - problems only with block elements. Check out). - ling
  • Yeah, everything is clear. =) - knes

Picture:

 <table> <tr valign = 'center' align = 'center'> <td rowspan = 2>20</td> <td style = 'border-bottom:1px solid black;'>4</td> <td rowspan = 2>06</td> </tr> <tr valign = 'center' align = 'center'> <td>V</td> </tr> </table> 

Algorithm for conversion to Roman numerals (JS):

 function rome( num ){ var d4 = [ '', 'M', 'MM', 'MMM' ], d3 = [ '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM' ], d2 = [ '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC' ], d1 = [ '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX' ]; return d4[ num /10000 % 1000 ] + d3[ num /1000 % 100 ] + d2[ num /100 % 10 ] + d1[ num %10 ]; } 

PS: The canonical representation of numbers greater than 3999 in Roman numerals is impossible

  • Oh, I already like that, although it is confusing to use the table. = / Something in me begins to itch at the thought of an inline table ... - knes