Skip to content

Instantly share code, notes, and snippets.

@moshekarmel1
Created January 28, 2016 20:32
Show Gist options
  • Save moshekarmel1/718027e80a55ae0e5818 to your computer and use it in GitHub Desktop.
Save moshekarmel1/718027e80a55ae0e5818 to your computer and use it in GitHub Desktop.
public void MikvaCalculation(int year, int month, int day){
Calendar calendar = new GregorianCalendar(year, month, day);
Calendar diffCal = new GregorianCalendar(year, month, day);
//get the date of the flow
mFlow.setSawBlood(calendar.getTime());
if(mFlow.isBeforeSunset()){//before shkiah...
day += 4;//add 4 days
calendar.set(year, month, day);
mFlow.setHefsekTahara(calendar.getTime());//hefsek tahara
day += 7;//add 7 days
calendar.set(year, month, day);
mFlow.setMikvaNight(calendar.getTime());//mikva night
day += 18;//add 18 days for day 30
}else{//after shkiah
day += 5;//plus one more day
calendar.set(year, month, day);
mFlow.setHefsekTahara(calendar.getTime());
day += 7;
calendar.set(year, month, day);
mFlow.setMikvaNight(calendar.getTime());
day += 17;
}
//day 30
calendar.set(year, month, day);
mFlow.setDay30(calendar.getTime());
//day 31
day += 1;
calendar.set(year, month, day);
mFlow.setDay31(calendar.getTime());
int diffInDays = 0;
if(previousFlow != null){
if(previousFlow.getTime() != 0){
long diff = mFlow.getSawBlood().getTime() - previousFlow.getTime();
diffInDays = (int) (diff / (24 * 60 * 60 * 1000));
diffInDays = figureOutDiff(isPreviousAfterSunset, mFlow.isBeforeSunset(), diffInDays);
//calculate diff like "32 days since last flow"
diffCal.add(Calendar.DATE, diffInDays);
mFlow.setHaflaga(diffCal.getTime());
diffInDays += 1; // add a day because the day itself counts as a day
mFlow.setHaflagaDiff(diffInDays);
}
}
//set the dates in the text views
sawBloodTV.setText(mFlow.getSawBloodString());
hefsekTaharaTV.setText(mFlow.getHefsekTaharaString());
mikvaNightTV.setText(mFlow.getMikvaNightString());
day30TV.setText(mFlow.getDay30String());
day31TV.setText(mFlow.getDay31String());
if(mFlow.getHaflaga() != null){
haflagaTV.setText(mFlow.getHaflagaString(diffInDays));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment