2010-03-29 16 views

risposta

0

LOL, provare a impostare l'ultima data selezionabile per 21 dicembre 2012? ma in realtà non finisce qui, si riavvia e vuoi ricominciare a contare dopo il 21 dicembre 2012?

1

Il modo migliore di utilizzare altri calendari/cronologie in Java è l'eccellente libreria Joda-Time. Non ha una cronologia Maya in sé, ma potresti correggere la tua implementazione delle regole Maya e collegarla. Non dovrebbe essere troppo oneroso.

+2

Non so se sia così facile, anche Jon Skeet ha puntato: http://msmvps.com/blogs/jon_skeet/archive/2009/11/06/noda-time-is-born.aspx#1738663 – Thilo

+0

Sta scrivendo una scala porta e vuole concentrarsi su questo piuttosto che su funzionalità aggiuntive come nuove cronologie. Penso che sia abbastanza giusto, senza indicare quanto sarebbe difficile scrivere una nuova cronologia. – GaryF

1

Utilizzare JodaTime. Ops, scusate, solo un riflesso quando si legge un messaggio riguardante java.util.Calendar ;-)

Ci sono alcuni Java applets sul web che potrebbe essere utile a voi.

6

Il tuo calendario è scaduto? :-)

+3

+1 Per divertimento –

1

Se sei veramente alla ricerca di una soluzione, questo Maya Calendar implementation sembra abbastanza buono.

Implementa un maya Tzolk'in calender utilizzando Java GregorianCalendar. Le date possono essere recuperate sia in formato Gregoriano o Tzolk'in.

Qui ci sono le parti fondamentali:

[...] 
/** parses Date specified in Long Count format, e.g. "12.19.19.17.19" */ 
public void parseLongCountDate (String longCountDate) { 
    String [] components = longCountDate.split("\\."); 
    try { 
      if (components.length != 5) 
       throw new Exception("Expecting 5 numbers separated by dots"); 
      int baktuns = Integer.valueOf(components[0]); 
      int katuns = Integer.valueOf(components[1]); 
      int tuns = Integer.valueOf(components[2]); 
      int winals = Integer.valueOf(components[3]); 
      int kins = Integer.valueOf(components[4]); 
      set (baktuns, katuns, tuns, winals, kins); 
    } catch (Throwable e) { 
      throw new IllegalArgumentException("Invalid long count date format: " 
      + e.getMessage()); 
    } 
} 

/** Set date to given long count date */ 
public void set (int baktuns, int katuns, int tuns, int uinals, int kins) { 
    assert MayaTimeUnit.Kin.toDays (1) == 1; 
    daysSinceGreatCycle = 
      MayaTimeUnit.Baktun.toDays (baktuns) + 
      MayaTimeUnit.Katun.toDays(katuns) + 
      MayaTimeUnit.Tun.toDays(tuns) + 
      MayaTimeUnit.Winal.toDays(uinals) + 
      kins; 
} 

[...] 

/** @return day name number in Tzolk'in calendar, e.g. it returns 0 (Ajaw) for the day "4 Ajaw" */ 
public Tzolkin toTzolkinDayName() { 
    // The Tzolk'in date is counted forward from 4 Ajaw. 
    return Tzolkin.DAYS[(daysSinceGreatCycle + 19) % 20]; // relative to Ajaw 
} 

/** @return day number in Tzolk'in calendar, e.g. it returns 4 for the day "4 Ajaw" */ 
public int toTzolkinDayNumber() { 
    // The Tzolk'in date is counted forward from 4 Ajaw. 
    return (daysSinceGreatCycle + 4) % 13; 
} 
[...] 

/** @return day name number in Haab calendar, e.g. it returns Yaxkin (5) for the day "14 Yaxk'in" */ 
public Haab toHaabDayName() { 
    int d = (daysSinceGreatCycle + 349) % 365; 
    return Haab.DAYS[d/20]; 
} 

/** @return day number in Haab calendar, e.g. it returns 14 for the day "14 Yaxk'in" */ 
public int toHaabDayNumber() { 
    int d = (daysSinceGreatCycle + 349) % 365; 
    return d % 20 - 1; 
} 
[...] 

/** @return Gregorian calendar representation of currently set date */ 
public String toGregorianString() { 
    Calendar c = toGregorianDate(); 
    return format.format(c.getTime()); 
} 

/** @return Converts currently defined date into Gregorian calendar */ 
public Calendar toGregorianDate() { 
    Calendar c = (Calendar)greatCycleStartDate.clone(); 
    c.add(Calendar.DAY_OF_YEAR, daysSinceGreatCycle); 
    return c; 
} 
[...] 

in ogni caso: fredda domanda :-)

Problemi correlati