Search in sources :

Example 21 with DateFormat

use of java.text.DateFormat in project OpenGrok by OpenGrok.

the class RazorHistoryParser method parseContents.

protected History parseContents(BufferedReader contents) throws IOException {
    DateFormat df = repository.getDateFormat();
    String line;
    ArrayList<HistoryEntry> entries = new ArrayList<HistoryEntry>();
    HistoryEntry entry = null;
    boolean ignoreEntry = false;
    boolean seenActionType = false;
    boolean lastWasTitle = true;
    Matcher actionMatcher = ACTION_TYPE_PATTERN.matcher("");
    Matcher infoMatcher = ADDITIONAL_INFO_PATTERN.matcher("");
    while ((line = contents.readLine()) != null) {
        parseDebug("Processing '" + line + "'");
        if (StringUtils.isOnlyWhitespace(line)) {
            if (entry != null && entry.getDate() != null) {
                entries.add(entry);
                dumpEntry(entry);
            }
            entry = new HistoryEntry();
            ignoreEntry = false;
            seenActionType = false;
        } else if (!ignoreEntry) {
            if (seenActionType) {
                infoMatcher.reset(line);
                if (infoMatcher.find()) {
                    String infoType = infoMatcher.group(1);
                    String details = infoMatcher.group(2);
                    if ("TITLE".equals(infoType)) {
                        parseDebug("Setting Message : '" + details + "'");
                        entry.setMessage(details);
                        lastWasTitle = true;
                    } else if ("ISSUE".equals(infoType)) {
                        parseDebug("Adding CR : '" + details + "'");
                        entry.addChangeRequest(details);
                    } else {
                        parseDebug("Ignoring Info Type Line '" + line + "'");
                    }
                } else {
                    if (!line.startsWith("##") && line.charAt(0) == '#') {
                        parseDebug("Seen Comment : '" + line + "'");
                        if (lastWasTitle) {
                            entry.appendMessage("");
                            lastWasTitle = false;
                        }
                        entry.appendMessage(line.substring(1));
                    } else {
                        parseProblem("Expecting addlInfo and got '" + line + "'");
                    }
                }
            } else {
                actionMatcher.reset(line);
                if (actionMatcher.find()) {
                    seenActionType = true;
                    if (entry != null && entry.getDate() != null) {
                        entries.add(entry);
                        dumpEntry(entry);
                    }
                    entry = new HistoryEntry();
                    String actionType = actionMatcher.group(1);
                    String userName = actionMatcher.group(2);
                    String revision = actionMatcher.group(3);
                    String state = actionMatcher.group(4);
                    String dateTime = actionMatcher.group(5);
                    parseDebug("New History Event Seen : actionType = " + actionType + ", userName = " + userName + ", revision = " + revision + ", state = " + state + ", dateTime = " + dateTime);
                    if (actionType.startsWith("INTRODUCE") || actionType.contains("CHECK-IN") || "CHECK-POINT".equals(actionType) || "REVERT".equals(actionType)) {
                        entry.setAuthor(userName);
                        entry.setRevision(revision);
                        entry.setActive("Active".equals(state));
                        Date date = null;
                        try {
                            date = df.parse(dateTime);
                        } catch (ParseException pe) {
                            //
                            throw new IOException("Could not parse date: " + dateTime, pe);
                        }
                        entry.setDate(date);
                        ignoreEntry = false;
                    } else {
                        ignoreEntry = true;
                    }
                } else {
                    parseProblem("Expecting actionType and got '" + line + "'");
                }
            }
        }
    }
    if (entry != null && entry.getDate() != null) {
        entries.add(entry);
        dumpEntry(entry);
    }
    History history = new History();
    history.setHistoryEntries(entries);
    return history;
}
Also used : Matcher(java.util.regex.Matcher) DateFormat(java.text.DateFormat) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) IOException(java.io.IOException) Date(java.util.Date)

Example 22 with DateFormat

use of java.text.DateFormat in project OpenGrok by OpenGrok.

the class SubversionRepositoryTest method testDateFormats.

@Test
public void testDateFormats() {
    String[][] tests = new String[][] { { "abcd", "expected exception" }, { "2016-01-01 10:00:00", "expected exception" }, { "2016 Sat, 1 Apr 2008 15:12:51 +0000", "expected exception" }, { "Sat, 1 Dub 2008 15:12:51 +0000", "expected exception" }, { "2016_01_01T10:00:00Z", "expected exception" }, { "2016-01-01T10:00:00T", "expected exception" }, { "2016-01-01T10:00:00.200", "expected exception" }, { "2016-01-01 10:00:00Z", "expected exception" }, // lenient - wrong hour
    { "2016-01-01T40:00:00Z", null }, // lenient - wrong minute
    { "2016-01-01T00:70:00Z", null }, // lenient - wrong second
    { "2016-01-01T00:00:99Z", null }, // lenient - wrong day
    { "2016-03-40T00:00:00Z", null }, { "2016-01-01T10:00:00.200Z", null }, { "2016-01-01T11:00:00.200Z", null }, { "2016-01-01T10:00:00.Z", null }, { "2017-01-01T10:00:00.Z", null }, { "2016-01-01T10:00:00Z", null } };
    DateFormat format = new SubversionRepository().getDateFormat();
    for (String[] test : tests) {
        try {
            format.parse(test[0]);
            if (test[1] != null) {
                Assert.fail("Shouldn't be able to parse the date: " + test[0]);
            }
        } catch (ParseException ex) {
            if (test[1] == null) {
                // no exception
                Assert.fail("Shouldn't throw a parsing exception for date: " + test[0]);
            }
        }
    }
}
Also used : DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 23 with DateFormat

use of java.text.DateFormat in project OpenGrok by OpenGrok.

the class RepositoryTest method testDateFormats.

@Test
public void testDateFormats() throws ParseException {
    String[][] tests = new String[][] { { "2016-01-01 10:00:00", "yyyy-MM-dd HH:mm:ss" }, { "2016 Sat, 5 Apr 2008 15:12:51 +0000", "yyyy EE, d MMM yyyy HH:mm:ss Z" }, { "Sat, 5 Apr 2008 15:12:51 +0000", "EE, d MMM yyyy HH:mm:ss Z" }, { "2016_01_01T10:00:00Z", "yyyy_MM_dd'T'HH:mm:ss'Z'" }, { "2016-01-01 10:00", "yyyy-MM-dd HH:mm" }, { "2016_01_01 10:00 +0000", "yyyy_MM_dd HH:mm Z" }, { "2016-01-01 10:00:00 +0000", "yyyy-MM-dd HH:mm:ss Z" }, { "2016-01-01 10:00 +0000", "yyyy-MM-dd HH:mm Z" }, { "2016-01-02 10:00 +0000", "yyyy-MM-dd HH:mm Z" }, { "2017-01-01 10:00 +0700", "yyyy-MM-dd HH:mm Z" }, { "2016-12-31 10:00 +0000", "yyyy-MM-dd HH:mm Z" } };
    for (String[] test : tests) {
        RepositoryImplementation repository = new RepositoryImplementation();
        repository.setDatePatterns(new String[] { test[1] });
        DateFormat format = repository.getDateFormat();
        format.parse(test[0]);
    }
}
Also used : DateFormat(java.text.DateFormat) Test(org.junit.Test)

Example 24 with DateFormat

use of java.text.DateFormat in project OpenGrok by OpenGrok.

the class RepositoryTest method testMultipleInvalidDateFormats.

@Test
public void testMultipleInvalidDateFormats() {
    String[][] tests = new String[][] { { "2016-01-01 10:00:00", "'abcd'", "MMM yy:ss ", "EE, d MMM yyyy Hss Z" }, { "2016 Sat, 5 Apr 2008 15:12:51 +0000", "yyyy d MMM yy:ss Z", "yyyy EE, d MMM ss Z" }, { "Sat, 5 Apr 2008 15:12:51 +0000", "d MMM yyyy Z", "EE, d MMM yyyy Hss Z" }, { "2016_01_01T10:00:00Z", "yyyy_MM_dd'T'ss'Z'" }, { "2016-01-01 10:00", "MM-dd Z", "EE-MM-dd HH", "Z dd-dd HH:mm" }, { "2016_01_01 10:00 +0000", "yyyy-MM_dd HH:mm Z" }, { "2016-01-01 10:00:00 +0000", "yyyy_MM_dd HH:s Z", "'bad format'" }, { "2016-01-01 10:00 +0000", "MM-d HH:mm", "yyyy-MM-dmm Z" }, { "2016-01-02 10:00 +0000", "yyyy-Mmm Z", "yyyy-M HH:mm Z" } };
    for (String[] test : tests) {
        RepositoryImplementation repository = new RepositoryImplementation();
        repository.setDatePatterns(Arrays.copyOfRange(test, 1, test.length));
        DateFormat format = repository.getDateFormat();
        try {
            format.parse(test[0]);
            Assert.fail("Shouldn't be able to parse the date: " + test[0]);
        } catch (ParseException ex) {
        }
    }
}
Also used : DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 25 with DateFormat

use of java.text.DateFormat in project actor-platform by actorapp.

the class CallFragment method startTimer.

protected void startTimer() {
    final DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
    formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    if (timer == null) {
        timer = ActorSystem.system().actorOf(Props.create(() -> new TimerActor(300)), "calls/timer");
        timer.send(new TimerActor.Register((currentTime, timeFromRegister) -> {
            if (getActivity() != null) {
                getActivity().runOnUiThread(() -> {
                    if (currentState == CallState.IN_PROGRESS) {
                        statusTV.setText(formatter.format(new Date(timeFromRegister)));
                    }
                });
            }
        }, TIMER_ID));
    }
}
Also used : BaseFragment(im.actor.sdk.controllers.BaseFragment) ImageButton(android.widget.ImageButton) Ringtone(android.media.Ringtone) PoisonPill(im.actor.runtime.actors.messages.PoisonPill) Bundle(android.os.Bundle) SurfaceViewRenderer(org.webrtc.SurfaceViewRenderer) PackageManager(android.content.pm.PackageManager) ActorSDKMessenger.groups(im.actor.sdk.util.ActorSDKMessenger.groups) Date(java.util.Date) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) Uri(android.net.Uri) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) PendingIntent(android.app.PendingIntent) Screen(im.actor.sdk.util.Screen) CallMember(im.actor.core.viewmodel.CallMember) Manifest(android.Manifest) PowerManager(android.os.PowerManager) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) View(android.view.View) DateFormat(java.text.DateFormat) Intents(im.actor.sdk.controllers.Intents) NotificationManager(android.app.NotificationManager) TimeZone(java.util.TimeZone) ValueModel(im.actor.runtime.mvvm.ValueModel) ContextCompat(android.support.v4.content.ContextCompat) ViewGroup(android.view.ViewGroup) ActorBinder(im.actor.sdk.controllers.ActorBinder) TextView(android.widget.TextView) Peer(im.actor.core.entity.Peer) Props(im.actor.runtime.actors.Props) Notification(android.app.Notification) CallState(im.actor.core.viewmodel.CallState) ViewHolder(im.actor.sdk.view.adapters.ViewHolder) Context(android.content.Context) ActorSDKMessenger.myUid(im.actor.sdk.util.ActorSDKMessenger.myUid) AndroidVideoTrack(im.actor.runtime.android.webrtc.AndroidVideoTrack) TintImageView(im.actor.sdk.view.TintImageView) SimpleDateFormat(java.text.SimpleDateFormat) Intent(android.content.Intent) GroupVM(im.actor.core.viewmodel.GroupVM) AudioManager(android.media.AudioManager) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) CallVM(im.actor.core.viewmodel.CallVM) MotionEvent(android.view.MotionEvent) GradientDrawable(android.graphics.drawable.GradientDrawable) ActorSystem(im.actor.runtime.actors.ActorSystem) AvatarView(im.actor.sdk.view.avatar.AvatarView) ActorRef(im.actor.runtime.actors.ActorRef) HolderAdapter(im.actor.sdk.view.adapters.HolderAdapter) PeerType(im.actor.core.entity.PeerType) ActorSDK(im.actor.sdk.ActorSDK) TimerActor(im.actor.sdk.controllers.calls.view.TimerActor) VideoRenderer(org.webrtc.VideoRenderer) LayoutInflater(android.view.LayoutInflater) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) Color(android.graphics.Color) Gravity(android.view.Gravity) UserVM(im.actor.core.viewmodel.UserVM) R(im.actor.sdk.R) CallBackgroundAvatarView(im.actor.sdk.view.avatar.CallBackgroundAvatarView) RingtoneManager(android.media.RingtoneManager) NotificationCompat(android.support.v4.app.NotificationCompat) EglBase(org.webrtc.EglBase) VideoTrack(org.webrtc.VideoTrack) Log(im.actor.runtime.Log) Vibrator(android.os.Vibrator) Activity(android.app.Activity) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) TimerActor(im.actor.sdk.controllers.calls.view.TimerActor) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

DateFormat (java.text.DateFormat)646 SimpleDateFormat (java.text.SimpleDateFormat)486 Date (java.util.Date)315 ParseException (java.text.ParseException)132 Calendar (java.util.Calendar)78 Test (org.junit.Test)69 ArrayList (java.util.ArrayList)48 IOException (java.io.IOException)43 File (java.io.File)31 HashMap (java.util.HashMap)27 GregorianCalendar (java.util.GregorianCalendar)24 TimeZone (java.util.TimeZone)23 Locale (java.util.Locale)18 Timestamp (java.sql.Timestamp)17 List (java.util.List)14 InputStream (java.io.InputStream)12 DateTime (org.joda.time.DateTime)11 Map (java.util.Map)10 Matcher (java.util.regex.Matcher)8 TestBean (org.springframework.tests.sample.beans.TestBean)8