/razpub/src/com/razie/pub/base/TimeOfDay.java

http://razpub.googlecode.com/ · Java · 58 lines · 36 code · 13 blank · 9 comment · 3 complexity · 6136530beb0aeb9c20430f616f41da2d MD5 · raw file

  1. /**
  2. * Razvan's public code. Copyright 2008 based on Apache license (share alike) see LICENSE.txt for
  3. * details.
  4. */
  5. package com.razie.pub.base;
  6. import java.util.Date;
  7. import razie.base.*;
  8. import com.razie.pub.base.data.RangeSel;
  9. /**
  10. * easy to use scriptable for date-time related stuff. I use it to play with scripting and presentation etc
  11. *
  12. * @author razvanc
  13. */
  14. public class TimeOfDay {
  15. public static String calcvalue() {return new TimeOfDay().value();}
  16. public TimeOfDay() {
  17. if (aivalues == null) {
  18. aivalues = new ActionItem[values.length];
  19. for (int i = 0; i < values.length; i++)
  20. aivalues[i] = new ActionItem(values[i]);
  21. }
  22. }
  23. public String[] tags() {
  24. return TAGS;
  25. }
  26. public ActionItem[] values() {
  27. return aivalues;
  28. }
  29. public String value() {
  30. Date dt = new Date();
  31. return new RangeSel<String>().rangeSel(dt.getHours(), rangei, values, dflt);
  32. }
  33. public ActionItem aivalue() {
  34. Date dt = new Date();
  35. return new RangeSel<ActionItem>().rangeSel(dt.getHours(), rangei, aivalues, aidflt);
  36. }
  37. static String[] TAGS = { "time" };
  38. int[][] rangei = { { 0, 6 }, { 7, 11 }, { 12, 19 }, { 20, 23 } };
  39. public static String[] values = { "night", "morning", "day", "evening" };
  40. String dflt = "?";
  41. ActionItem[] aivalues;
  42. ActionItem aidflt = new ActionItem("?");
  43. String[][] ranges = { { "0", "6", "night" }, { "7", "11", "morning" }, { "12", "18", "day" },
  44. { "19", "23", "evening" } };
  45. }