Package name.pehl.karaka.shared.model

Examples of name.pehl.karaka.shared.model.Duration


        DateMidnight now = now(settings.get().getTimeZone());
        int year = now.year().get();
        int month = now.monthOfYear().get();
        int week = now.weekOfWeekyear().get();
        int day = now.dayOfMonth().get();
        Duration currentMonth = minutes(repository.findByYearMonth(year, month));
        Duration currentWeek = minutes(repository.findByYearWeek(year, week));
        Duration today = minutes(repository.findByYearMonthDay(year, month, day));
        Durations durations = new Durations(currentMonth, currentWeek, today);

        String url = uriInfo.getAbsolutePath().toASCIIString();
        LinkHeader linkHeader = new LinkHeader().addLink(null, SELF, url, null);
        return Response.ok(durations).header("Link", linkHeader.toString()).build();
View Full Code Here


        long minutes = 0;
        for (Activity activity : activities)
        {
            minutes += activity.getDuration();
        }
        return new Duration(minutes);
    }
View Full Code Here

                new name.pehl.karaka.shared.model.Time(entity.getStart().toDate(), entity.getStart()
                        .getYear(), entity.getStart().getMonth(), entity.getStart().getWeek(),
                        entity.getStart().getDay()));
        model.setEnd(new name.pehl.karaka.shared.model.Time(entity.getEnd().toDate(), entity.getEnd()
                .getYear(), entity.getEnd().getMonth(), entity.getEnd().getWeek(), entity.getEnd().getDay()));
        model.setPause(new Duration(entity.getPause()));
        model.setDuration(new Duration(entity.getDuration()));
        model.setBillable(entity.isBillable());
        model.setStatus(entity.getStatus());

        // relations
        if (entity.getProject() != null && entity.getProject().get() != null)
View Full Code Here

    static final RegExp REGEXP = RegExp.compile("([0-9]+)([.,:]?)([0-9]*)([hm]?)");


    public Duration parse(String time) throws ParseException
    {
        Duration result = Duration.ZERO;
        if (time != null && time.trim().length() != 0)
        {
            if (!REGEXP.test(time))
            {
                throw new ParseException("Illegal time: \"" + time + "\"");
            }
            MatchResult match = REGEXP.exec(time);
            String hoursGroup = match.getGroup(1);
            if (!time.startsWith(hoursGroup))
            {
                throw new ParseException("Illegal time: \"" + time + "\"");
            }
            long hours = asLong(hoursGroup);
            Seperator seperator = asSeperator(match.getGroup(2));
            long minutes = asLong(match.getGroup(3));
            Unit unit = asUnit(match.getGroup(4));

            if (seperator == COLUMN)
            {
                // Unit is ignored!
                if (hours < 0 || hours > 23)
                {
                    throw new ParseException("Hour is out of range [0-23]");
                }
                if (minutes < 0 || minutes > 59)
                {
                    throw new ParseException("Minute is out of range [0-59]");
                }
            }
            else
            {
                if (unit == Unit.NONE || unit == HOURS)
                {
                    if (hours < 0 || hours > 23)
                    {
                        throw new ParseException("Hour is out of range [0-23]");
                    }
                    if (minutes < 0 || minutes > 99)
                    {
                        throw new ParseException("Minute is out of range [0-99]");
                    }
                    if (minutes < 10)
                    {
                        minutes *= 10;
                    }
                    minutes *= .6;
                }
                else
                {
                    minutes = hours;
                    hours = 0;
                    if (minutes < 0 || minutes > 1439)
                    {
                        throw new ParseException("Minute is out of range [0-1439]");
                    }
                }
            }
            result = new Duration(hours, minutes);
        }
        return result;
    }
View Full Code Here

    @Override
    public void onValueChange(ValueChangeEvent<String> event)
    {
        try
        {
            Duration d = durationParser.parse(event.getValue());
            currentValue = d;
            ValueChangeEvent.fire(this, currentValue);
        }
        catch (ParseException e)
        {
View Full Code Here

        if (isValid(value))
        {
            try
            {
                long d = Long.valueOf(value);
                return new Duration(d);
            }
            catch (NumberFormatException e)
            {
                return Duration.ZERO;
            }
View Full Code Here

    // --------------------------------------------------- null / empty / blank

    @Test
    public void nil() throws ParseException
    {
        Duration duration = cut.parse(null);
        assertEquals(Duration.ZERO, duration);
    }
View Full Code Here


    @Test
    public void empty() throws ParseException
    {
        Duration duration = cut.parse("");
        assertEquals(Duration.ZERO, duration);
    }
View Full Code Here


    @Test
    public void blank() throws ParseException
    {
        Duration duration = cut.parse("    ");
        assertEquals(Duration.ZERO, duration);
    }
View Full Code Here

    public void hoursOk() throws ParseException
    {
        String[] times = new String[] {"1", "01", "1h", "01h", "1:", "01:", "1.", "01.", "1,", "01,"};
        for (String time : times)
        {
            Duration duration = cut.parse(time);
            assertEquals("Error parsing " + time, 1, duration.getHours());
            assertEquals("Error parsing " + time, 0, duration.getMinutes());
        }
    }
View Full Code Here

TOP

Related Classes of name.pehl.karaka.shared.model.Duration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.