1 25 26 29 package net.killingar.forum.comics; 30 31 import java.util.Calendar ; 32 import java.util.Date ; 33 34 public class DieselSweetiesFormatter extends java.text.Format 35 { 36 protected int minNumberOfDigits = 3; 38 public Object parseObject(String source, java.text.ParsePosition status) 39 { 40 return null; 41 } 42 43 public StringBuffer format(Object obj, StringBuffer toAppendTo, java.text.FieldPosition pos) 44 { 45 if (obj instanceof Date ) 46 return toAppendTo.append(format((Date )obj)); 47 else 48 throw new IllegalArgumentException (); 49 } 50 51 public String adjustString(String s) 52 { 53 for (int i = s.length(); i < minNumberOfDigits; i++) 54 s = "0"+s; 55 56 return s; 57 } 58 59 public final String format(Date date) 60 { 61 Calendar tmpCal = Calendar.getInstance(), calendar = Calendar.getInstance(); 62 int i = 0; 63 calendar.clear(); 64 tmpCal.setTime(date); 65 66 while (calendar.get(Calendar.YEAR) < tmpCal.get(Calendar.YEAR)) 67 { 68 calendar.add(Calendar.YEAR, 1); 69 calendar.add(Calendar.DATE, -1); 70 i += calendar.get(Calendar.DAY_OF_YEAR); 71 calendar.add(Calendar.DATE, 1); 72 } 73 74 return adjustString(Integer.toString(i+tmpCal.get(Calendar.DAY_OF_YEAR))); 75 } 76 } 77 | Popular Tags |