01: /******************************************************************************
02: * Copyright (C) Lars Ivar Almli. All rights reserved. *
03: * ---------------------------------------------------------------------------*
04: * This file is part of MActor. *
05: * *
06: * MActor is free software; you can redistribute it and/or modify *
07: * it under the terms of the GNU General Public License as published by *
08: * the Free Software Foundation; either version 2 of the License, or *
09: * (at your option) any later version. *
10: * *
11: * MActor is distributed in the hope that it will be useful, *
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14: * GNU General Public License for more details. *
15: * *
16: * You should have received a copy of the GNU General Public License *
17: * along with MActor; if not, write to the Free Software *
18: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
19: ******************************************************************************/package org.mactor.extensions;
20:
21: import java.text.SimpleDateFormat;
22: import java.util.Calendar;
23: import java.util.List;
24: import org.mactor.framework.MactorException;
25: import org.mactor.framework.TestContext;
26: import org.mactor.framework.extensioninterface.ValueCommand;
27:
28: /**
29: * Extracts the current time on the format: 'yyyy-MM-dd'T'HH:mm:ss.SSSZ'
30: * <br>
31: * A single parameter can be provided to specify the number of minutes to add to or substract from the current time (5 adds five minuts -120 subtracts to hours )
32: *
33: * @author Lars Ivar Almli
34: */
35: public class CurrentTimeExtractor implements ValueCommand {
36: public String extractValue(TestContext context, List<String> params)
37: throws MactorException {
38: Calendar cal = Calendar.getInstance();
39: if (params != null && params.size() > 0
40: && params.get(0) != null && params.get(0).length() > 0) {
41: try {
42: String v = params.get(0);
43: int minutes = Integer.parseInt(v);
44: cal.add(Calendar.MINUTE, minutes);
45: } catch (NumberFormatException nfe) {
46: }
47: }
48: String s = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
49: .format(cal.getTime());
50: if (s.charAt(s.length() - 2) != ':') // Bug in SimpleDateFormat?
51: s = s.substring(0, s.length() - 2) + ":"
52: + s.substring(s.length() - 2);
53: return s;
54: }
55: }
|