Example usage for org.joda.time DateTime getDayOfMonth

List of usage examples for org.joda.time DateTime getDayOfMonth

Introduction

In this page you can find the example usage for org.joda.time DateTime getDayOfMonth.

Prototype

public int getDayOfMonth() 

Source Link

Document

Get the day of month field value.

Usage

From source file:org.jimcat.gui.histogram.image.DateTakenDimension.java

License:Open Source License

/**
 * get mark for index//from  ww  w  . ja  va  2  s . c  o  m
 * 
 * @see org.jimcat.gui.histogram.image.Dimension#getMarkFor(int, int)
 */
@Override
public ScaleMark getMarkFor(int resolution, int index) {
    ScaleMark result = ScaleMark.SMALL;

    // get corresponding date
    DateTime date = indexToDate(resolution, index);
    if (date == null) {
        // no data available
        return ScaleMark.NONE;
    }

    if (resolution == DAYS) {
        int day = date.getDayOfMonth();
        if (day == 1 || day == 15) {
            result = ScaleMark.LABEL;
        }
    } else if (resolution == WEEKS) {
        int week = date.getWeekOfWeekyear();
        if (week == 1 || week % 10 == 0) {
            result = ScaleMark.LABEL;
        }
    } else if (resolution == MONTHS) {
        int month = date.getMonthOfYear();
        if (month % 3 == 0) {
            result = ScaleMark.LABEL;
        }
    }

    return result;
}

From source file:org.jimcat.services.rename.Renamer.java

License:Open Source License

@SuppressWarnings("null")
private String getNewName(Image image, int n) {
    String newName = configString;
    DateTime date = null;

    switch (useDate) {
    case MODIFICATION:
        date = image.getMetadata().getModificationDate();
        break;/*from  w w  w . java 2  s  .c  om*/
    case ADDED:
        date = image.getMetadata().getDateAdded();
        break;
    case TAKEN:

        ExifMetadata exifMetadata = image.getExifMetadata();

        if (exifMetadata != null) {
            date = exifMetadata.getDateTaken();
        }
        break;
    }

    String random;

    do {
        random = String.valueOf(Math.random());
    } while (configString.contains(random));

    if (hasParameter(escapeCharacter.charAt(0))) {
        newName = newName.replace(escapeCharacter + escapeCharacter, random);
    }

    if (hasParameter('n')) {
        String number = String.format("%0" + digits + "d", new Integer(n));
        newName = newName.replace(escapeCharacter + "n", number);
    }

    if (hasParameter('w')) {
        newName = newName.replace(escapeCharacter + "w", "" + image.getMetadata().getWidth());
    }

    if (hasParameter('h')) {
        newName = newName.replace(escapeCharacter + "h", "" + image.getMetadata().getHeight());
    }

    if (hasParameter('d')) {
        if (date == null) {
            newName = newName.replace(escapeCharacter + "d", unknownResultCharacter);
        } else {
            String day = formatNumber(date.getDayOfMonth(), 2);
            newName = newName.replace(escapeCharacter + "d", day);
        }
    }

    if (hasParameter('m')) {
        if (date == null) {
            newName = newName.replace(escapeCharacter + "m", unknownResultCharacter);
        } else {
            String month = formatNumber(date.getMonthOfYear(), 2);
            newName = newName.replace(escapeCharacter + "m", month);
        }
    }

    if (hasParameter('y')) {
        if (date == null) {
            newName = newName.replace(escapeCharacter + "y", unknownResultCharacter);
        } else {
            String year = formatNumber(date.getYear(), 4);
            newName = newName.replace(escapeCharacter + "y", year);
        }
    }

    if (hasParameter('H')) {
        if (date == null) {
            newName = newName.replace(escapeCharacter + "H", unknownResultCharacter);
        } else {
            String hour = formatNumber(date.getHourOfDay(), 2);
            newName = newName.replace(escapeCharacter + "H", hour);
        }
    }

    if (hasParameter('M')) {
        if (date == null) {
            newName = newName.replace(escapeCharacter + "M", unknownResultCharacter);
        } else {
            String minute = formatNumber(date.getMinuteOfHour(), 2);
            newName = newName.replace(escapeCharacter + "M", minute);
        }
    }

    if (hasParameter('S')) {
        if (date == null) {
            newName = newName.replace(escapeCharacter + "S", unknownResultCharacter);
        } else {
            String seconds = formatNumber(date.getSecondOfMinute(), 2);
            newName = newName.replace(escapeCharacter + "S", seconds);
        }
    }

    if (hasParameter('r')) {
        newName = newName.replace(escapeCharacter + "r", ratingToString(image.getRating()));
    }

    if (hasParameter('f')) {
        if (image.getMetadata() != null && image.getMetadata().getPath() != null) {
            String fileName = removeFileType(image.getMetadata().getPath());
            newName = newName.replace(escapeCharacter + "f", fileName);
        } else {
            newName = newName.replace(escapeCharacter + "f", unknownResultCharacter);
        }
    }

    if (newName.length() == 0) {
        return newName;
    }

    // if the user is just typing dont show the last $
    // but if he wants a $ at the and (by using $$) allow it and even allow
    // $$ at the end

    int escapeCharactersAtEnd = 0;
    int index = newName.length() - 1;

    while (index >= 0 && newName.charAt(index--) == escapeCharacter.charAt(0)) {
        escapeCharactersAtEnd++;
    }

    if (escapeCharactersAtEnd % 2 == 1) {
        newName = newName.substring(0, newName.length() - 1);
    }

    if (hasParameter(escapeCharacter.charAt(0))) {
        newName = newName.replace(random, escapeCharacter);
    }

    // set at the end because the original title could contain evil control
    // sequences
    if (hasParameter('t')) {
        newName = newName.replace(escapeCharacter + "t", image.getTitle());
    }

    return newName;
}

From source file:org.joda.example.time.DateTimePerformance.java

License:Apache License

private void checkJodaGetDay() {
    int COUNT = COUNT_VERY_FAST;
    DateTime dt = new DateTime(GJChronology.getInstance());
    for (int i = 0; i < AVERAGE; i++) {
        start("Joda", "getDay");
        for (int j = 0; j < COUNT; j++) {
            int val = dt.getDayOfMonth();
            if (val == 0) {
                System.out.println("Anti optimise");
            }/*from  w w w .  j  a v  a2s . co  m*/
        }
        end(COUNT);
    }
}

From source file:org.joda.example.time.DateTimePerformance.java

License:Apache License

private void checkJISOGetDay() {
    int COUNT = COUNT_VERY_FAST;
    DateTime dt = new DateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "getDay");
        for (int j = 0; j < COUNT; j++) {
            int val = dt.getDayOfMonth();
            if (val == 0) {
                System.out.println("Anti optimise");
            }/*w ww. j a v a  2  s . co  m*/
        }
        end(COUNT);
    }
}

From source file:org.joda.example.time.Examples.java

License:Apache License

private void runDateTime() {
    System.out.println("DateTime");
    System.out.println("=======");
    System.out.println(/*w w  w  . j a va2  s.  c o m*/
            "DateTime stores a the date and time using millisecs from 1970-01-01T00:00:00Z internally");
    System.out.println("DateTime is immutable and thread-safe");
    System.out.println("                      in = new DateTime()");
    DateTime in = new DateTime();
    System.out.println("Millisecond time:     in.getMillis():           " + in.getMillis());
    System.out.println("ISO string version:   in.toString():            " + in.toString());
    System.out.println("ISO chronology:       in.getChronology():       " + in.getChronology());
    System.out.println("Your time zone:       in.getDateTimeZone():     " + in.getZone());
    System.out.println("Change millis:        in.withMillis(0):         " + in.withMillis(0L));
    System.out.println("");
    System.out.println("Get year:             in.getYear():             " + in.getYear());
    System.out.println("Get monthOfYear:      in.getMonthOfYear():      " + in.getMonthOfYear());
    System.out.println("Get dayOfMonth:       in.getDayOfMonth():       " + in.getDayOfMonth());
    System.out.println("...");
    System.out.println("Property access:      in.dayOfWeek().get():                   " + in.dayOfWeek().get());
    System.out.println(
            "Day of week as text:  in.dayOfWeek().getAsText():             " + in.dayOfWeek().getAsText());
    System.out.println(
            "Day as short text:    in.dayOfWeek().getAsShortText():        " + in.dayOfWeek().getAsShortText());
    System.out.println("Day in french:        in.dayOfWeek().getAsText(Locale.FRENCH):"
            + in.dayOfWeek().getAsText(Locale.FRENCH));
    System.out.println("Max allowed value:    in.dayOfWeek().getMaximumValue():       "
            + in.dayOfWeek().getMaximumValue());
    System.out.println("Min allowed value:    in.dayOfWeek().getMinimumValue():       "
            + in.dayOfWeek().getMinimumValue());
    System.out.println(
            "Copy & set to Jan:    in.monthOfYear().setCopy(1):            " + in.monthOfYear().setCopy(1));
    System.out.println(
            "Copy & add 14 months: in.monthOfYear().addCopy(14):           " + in.monthOfYear().addToCopy(14));
    System.out.println("Add 14 mnths in field:in.monthOfYear().addWrapFieldCopy(14):  "
            + in.monthOfYear().addWrapFieldToCopy(14));
    System.out.println("...");
    System.out.println("Convert to Instant:   in.toInstant():           " + in.toInstant());
    System.out.println("Convert to DateTime:  in.toDateTime():          " + in.toDateTime());
    System.out.println("Convert to MutableDT: in.toMutableDateTime():   " + in.toMutableDateTime());
    System.out.println("Convert to Date:      in.toDate():              " + in.toDate());
    System.out.println("Convert to Calendar:  in.toCalendar(Locale.UK): "
            + in.toCalendar(Locale.UK).toString().substring(0, 46));
    System.out.println("Convert to GregCal:   in.toGregorianCalendar(): "
            + in.toGregorianCalendar().toString().substring(0, 46));
    System.out.println("");
    System.out.println("                      in2 = new DateTime(in.getMillis() + 10)");
    DateTime in2 = new DateTime(in.getMillis() + 10);
    System.out.println("Equals ms and chrono: in.equals(in2):           " + in.equals(in2));
    System.out.println("Compare millisecond:  in.compareTo(in2):        " + in.compareTo(in2));
    System.out.println("Compare millisecond:  in.isEqual(in2):          " + in.isEqual(in2));
    System.out.println("Compare millisecond:  in.isAfter(in2):          " + in.isAfter(in2));
    System.out.println("Compare millisecond:  in.isBefore(in2):         " + in.isBefore(in2));
}

From source file:org.jruby.ext.date.RubyDate.java

License:LGPL

@JRubyMethod // Time.local(year, mon, mday)
public RubyTime to_time(ThreadContext context) {
    final Ruby runtime = context.runtime;
    DateTime dt = this.dt;

    dt = new DateTime(adjustJodaYear(dt.getYear()), dt.getMonthOfYear(), dt.getDayOfMonth(), 0, 0, 0,
            RubyTime.getLocalTimeZone(runtime));
    return new RubyTime(runtime, runtime.getTime(), dt);
}

From source file:org.jruby.ext.date.RubyDateTime.java

License:LGPL

@JRubyMethod // Time.new(year, mon, mday, hour, min, sec + sec_fraction, (@of * 86400.0))
public RubyTime to_time(ThreadContext context) {
    final Ruby runtime = context.runtime;
    DateTime dt = this.dt;

    dt = new DateTime(adjustJodaYear(dt.getYear()), dt.getMonthOfYear(), dt.getDayOfMonth(), dt.getHourOfDay(),
            dt.getMinuteOfHour(), dt.getSecondOfMinute(), dt.getMillisOfSecond(),
            RubyTime.getTimeZone(runtime, this.off));

    RubyTime time = new RubyTime(runtime, runtime.getTime(), dt, true);
    if (subMillisNum != 0) {
        RubyNumeric usec = (RubyNumeric) subMillis(runtime).op_mul(context,
                RubyFixnum.newFixnum(runtime, 1_000_000));
        time.setNSec(usec.getLongValue());
    }//  w  ww.  j  a  v a  2  s. c o  m
    return time;
}

From source file:org.jruby.ext.date.TimeExt.java

License:LGPL

@JRubyMethod(name = "to_date")
public static RubyDate to_date(ThreadContext context, IRubyObject self) {
    final DateTime dt = ((RubyTime) self).getDateTime();
    long jd = civil_to_jd(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), GREGORIAN);
    return new RubyDate(context, getDate(context.runtime), jd_to_ajd(context, jd), CHRONO_ITALY_UTC, 0);
}

From source file:org.jruby.ext.date.TimeExt.java

License:LGPL

@JRubyMethod(name = "to_datetime")
public static RubyDateTime to_datetime(ThreadContext context, IRubyObject self) {
    final RubyTime time = (RubyTime) self;
    DateTime dt = ((RubyTime) self).getDateTime();

    long subMillisNum = 0, subMillisDen = 1;
    if (time.getNSec() != 0) {
        IRubyObject subMillis = RubyRational.newRationalCanonicalize(context, time.getNSec(), 1_000_000);
        if (subMillis instanceof RubyRational) {
            subMillisNum = ((RubyRational) subMillis).getNumerator().getLongValue();
            subMillisDen = ((RubyRational) subMillis).getDenominator().getLongValue();
        } else {/*from   www. java  2 s  .  co m*/
            subMillisNum = ((RubyInteger) subMillis).getLongValue();
        }
    }

    final int off = dt.getZone().getOffset(dt.getMillis()) / 1000;

    int year = dt.getYear();
    if (year <= 0)
        year--; // JODA's Julian chronology (no year 0)

    if (year == 1582) { // take the "slow" path -  JODA isn't adjusting for missing (reform) dates
        return calcAjdFromCivil(context, dt, off, subMillisNum, subMillisDen);
    }

    dt = new DateTime(year, dt.getMonthOfYear(), dt.getDayOfMonth(), dt.getHourOfDay(), dt.getMinuteOfHour(),
            dt.getSecondOfMinute(), dt.getMillisOfSecond(), getChronology(context, ITALY, dt.getZone()));

    return new RubyDateTime(context.runtime, getDateTime(context.runtime), dt, off, ITALY, subMillisNum,
            subMillisDen);
}

From source file:org.jruby.ext.date.TimeExt.java

License:LGPL

private static RubyDateTime calcAjdFromCivil(ThreadContext context, final DateTime dt, final int off,
        final long subMillisNum, final long subMillisDen) {
    final Ruby runtime = context.runtime;

    long jd = civil_to_jd(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), ITALY);
    RubyNumeric fr = timeToDayFraction(context, dt.getHourOfDay(), dt.getMinuteOfHour(),
            dt.getSecondOfMinute());//from  w ww .j  av  a  2s  .c  om

    final RubyNumeric ajd = jd_to_ajd(context, jd, fr, off);
    RubyDateTime dateTime = new RubyDateTime(context, getDateTime(runtime), ajd, off, ITALY);
    dateTime.dt = dateTime.dt.withMillisOfSecond(dt.getMillisOfSecond());
    dateTime.subMillisNum = subMillisNum;
    dateTime.subMillisDen = subMillisDen;
    return dateTime;
}