getXunIndex static method

int getXunIndex(
  1. String ganZhi
)

Implementation

static int getXunIndex(String ganZhi) {
  String gan = ganZhi.substring(0, 1);
  String zhi = ganZhi.substring(1);
  int ganIndex = 0;
  int zhiIndex = 0;
  for (int i = 0, j = GAN.length; i < j; i++) {
    if (GAN[i] == gan) {
      ganIndex = i;
      break;
    }
  }
  for (int i = 0, j = ZHI.length; i < j; i++) {
    if (ZHI[i] == zhi) {
      zhiIndex = i;
      break;
    }
  }
  int diff = ganIndex - zhiIndex;
  if (diff < 0) {
    diff += 12;
  }
  return (diff / 2).floor();
}