PageRenderTime 25ms CodeModel.GetById 16ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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 */
 5package com.razie.pub.base;
 6
 7import java.util.Date;
 8import razie.base.*;
 9import com.razie.pub.base.data.RangeSel;
10
11/**
12 * easy to use scriptable for date-time related stuff. I use it to play with scripting and presentation etc
13 * 
14 * @author razvanc
15 */
16public class TimeOfDay {
17
18    public static String calcvalue() {return new TimeOfDay().value();}
19    
20    public TimeOfDay() {
21        if (aivalues == null) {
22            aivalues = new ActionItem[values.length];
23
24            for (int i = 0; i < values.length; i++)
25                aivalues[i] = new ActionItem(values[i]);
26        }
27    }
28
29    public String[] tags() {
30        return TAGS;
31    }
32
33    public ActionItem[] values() {
34        return aivalues;
35    }
36
37    public String value() {
38        Date dt = new Date();
39        return new RangeSel<String>().rangeSel(dt.getHours(), rangei, values, dflt);
40    }
41
42    public ActionItem aivalue() {
43        Date dt = new Date();
44        return new RangeSel<ActionItem>().rangeSel(dt.getHours(), rangei, aivalues, aidflt);
45    }
46
47    static String[] TAGS   = { "time" };
48
49    int[][]         rangei = { { 0, 6 }, { 7, 11 }, { 12, 19 }, { 20, 23 } };
50    public static String[]        values = { "night", "morning", "day", "evening" };
51    String          dflt   = "?";
52
53    ActionItem[]    aivalues;
54    ActionItem      aidflt = new ActionItem("?");
55
56    String[][]      ranges = { { "0", "6", "night" }, { "7", "11", "morning" }, { "12", "18", "day" },
57            { "19", "23", "evening" } };
58}