Example usage for java.util Calendar WEEK_OF_YEAR

List of usage examples for java.util Calendar WEEK_OF_YEAR

Introduction

In this page you can find the example usage for java.util Calendar WEEK_OF_YEAR.

Prototype

int WEEK_OF_YEAR

To view the source code for java.util Calendar WEEK_OF_YEAR.

Click Source Link

Document

Field number for get and set indicating the week number within the current year.

Usage

From source file:org.mot.common.util.DateBuilder.java

public int getWeekOfYear(Date input) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(input);
    return cal.get(Calendar.WEEK_OF_YEAR);
}

From source file:system.controllers.KeywordApp.java

public static String getExcelName(String type, String startDate, String endDate) {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Calendar cal = Calendar.getInstance();
    cal.getTime();//from   w w  w . j  a v a 2 s  . c o  m
    if ("".equals(type)) {
        cal.add(Calendar.DAY_OF_MONTH, -1);
        return df.format(cal.getTime());
    } else if ("0".equals(type)) {
        cal.add(Calendar.WEEK_OF_YEAR, -1);
        return cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.WEEK_OF_YEAR) + "";
    } else if ("1".equals(type)) {
        return cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "";
    } else if ("2".equals(type)) {
        return startDate + "-" + endDate;
    }
    return "";
}

From source file:com.bjorsond.android.timeline.utilities.Utilities.java

public static boolean isSameWeek(Date date1, Date date2) {
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    cal1.setTime(date1);/*from  w w  w. jav  a2s. com*/
    cal2.setTime(date2);
    boolean sameWeek = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
            && cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR);
    return sameWeek;
}

From source file:de.forsthaus.webui.calendar.model.CalendarDateFormatter.java

/**
 * Returns the number of week of the year in month mold .<br>
 * EN: .<br>/*www . j  ava 2  s . co  m*/
 * DE: .<br>
 */
@Override
public String getCaptionByWeekOfYear(Date date, Locale locale, TimeZone timezone) {
    Calendar cal = Calendar.getInstance(timezone, locale);
    cal.setTime(date);
    return String.valueOf(cal.get(Calendar.WEEK_OF_YEAR));
}

From source file:fr.dutra.confluence2wordpress.core.metadata.DefaultMetadataManager.java

public Metadata createMetadata(ContentEntityObject page, Set<WordpressUser> users,
        Set<WordpressCategory> categories) {
    Metadata metadata = new Metadata();
    String pageTitle = page.getTitle();
    Matcher matcher = DRAFT_PREFIX_PATTERN.matcher(pageTitle);
    if (matcher.matches()) {
        String prefix = matcher.group(1);
        metadata.setPageTitle(StringUtils.substringAfter(pageTitle, prefix));
    } else {//from  w w w.j  a v  a2  s. c o  m
        metadata.setPageTitle(pageTitle);
    }
    if (StringUtils.containsIgnoreCase(metadata.getPageTitle(), RDP_CATEGORY_NAME)) {
        metadata.setPageTitle(RDP_PAGE_TITLE); // to normalize the title
        if (categories != null) {
            for (WordpressCategory category : categories) {
                if (StringUtils.containsIgnoreCase(category.getCategoryName(), RDP_CATEGORY_NAME)) {
                    metadata.setCategoryNames(Collections.singletonList(category.getCategoryName()));
                    break;
                }
            }
        }
        Calendar now = Calendar.getInstance();
        metadata.setPostSlug(
                String.format(RDP_POST_SLUG_FORMAT, now.getTime(), now.get(Calendar.WEEK_OF_YEAR)));
        if (users != null) {
            for (WordpressUser user : users) {
                if (XEBIA_FRANCE_LOGIN.equals(user.getLogin())) {
                    metadata.setAuthorId(user.getId());
                    break;
                }
            }
        }
    } else {
        String creatorName = page.getCreatorName();
        if (creatorName != null && users != null) {
            for (WordpressUser wordpressUser : users) {
                if (creatorName.equals(wordpressUser.getLogin())) {
                    metadata.setAuthorId(wordpressUser.getId());
                    break;
                }
            }
        }
    }
    return metadata;
}

From source file:org.mot.common.util.DateBuilder.java

public int getWeekOfYear() {
    Calendar cal = Calendar.getInstance();
    cal.setTime(this.getDate());
    return cal.get(Calendar.WEEK_OF_YEAR);
}

From source file:org.callimachusproject.sql.SqlTupleResult.java

private Value value(int col) throws SQLException {
    int type = md.getColumnType(col);
    String str = rs.getString(col);
    if (str == null)
        return null;
    switch (type) {
    case java.sql.Types.NULL:
        return null;
    case java.sql.Types.DATALINK:
        return vf.createURI(str);
    case java.sql.Types.BINARY:
    case java.sql.Types.VARBINARY:
    case java.sql.Types.BIT:
    case java.sql.Types.BLOB:
    case java.sql.Types.LONGVARBINARY:
    case java.sql.Types.JAVA_OBJECT:
        return vf.createLiteral(Hex.encodeHexString(rs.getBytes(col)), XMLSchema.HEXBINARY);
    case java.sql.Types.DECIMAL:
    case java.sql.Types.NUMERIC:
        return vf.createLiteral(str, XMLSchema.DECIMAL);
    case java.sql.Types.TINYINT:
    case java.sql.Types.SMALLINT:
    case java.sql.Types.INTEGER:
    case java.sql.Types.BIGINT:
        return vf.createLiteral(str, XMLSchema.INTEGER);
    case java.sql.Types.DOUBLE:
    case java.sql.Types.FLOAT:
    case java.sql.Types.REAL:
        return vf.createLiteral(str, XMLSchema.DOUBLE);
    case java.sql.Types.BOOLEAN:
        return vf.createLiteral(rs.getBoolean(col));
    case java.sql.Types.DATE:
        GregorianCalendar date = new GregorianCalendar();
        date.setTime(rs.getDate(col));//from   ww  w.j  a v  a 2  s .c o  m
        date.clear(Calendar.AM_PM);
        date.clear(Calendar.HOUR);
        date.clear(Calendar.HOUR_OF_DAY);
        date.clear(Calendar.MINUTE);
        date.clear(Calendar.SECOND);
        date.clear(Calendar.MILLISECOND);
        return vf.createLiteral(df.newXMLGregorianCalendar(date));
    case java.sql.Types.TIME:
        GregorianCalendar time = new GregorianCalendar();
        time.setTime(rs.getTime(col));
        time.clear(Calendar.ERA);
        time.clear(Calendar.YEAR);
        time.clear(Calendar.MONTH);
        time.clear(Calendar.WEEK_OF_YEAR);
        time.clear(Calendar.WEEK_OF_MONTH);
        time.clear(Calendar.DATE);
        time.clear(Calendar.DAY_OF_MONTH);
        time.clear(Calendar.DAY_OF_YEAR);
        time.clear(Calendar.DAY_OF_WEEK);
        time.clear(Calendar.DAY_OF_WEEK_IN_MONTH);
        return vf.createLiteral(df.newXMLGregorianCalendar(time));
    case java.sql.Types.TIMESTAMP:
        return vf.createLiteral(rs.getTimestamp(col));
    case java.sql.Types.SQLXML:
        return vf.createLiteral(str, RDF.XMLLITERAL);
    case java.sql.Types.ARRAY:
    case java.sql.Types.CHAR:
    case java.sql.Types.CLOB:
    case java.sql.Types.DISTINCT:
    case java.sql.Types.LONGNVARCHAR:
    case java.sql.Types.NCHAR:
    case java.sql.Types.NCLOB:
    case java.sql.Types.NVARCHAR:
    case java.sql.Types.OTHER:
    case java.sql.Types.REF:
    case java.sql.Types.ROWID:
    case java.sql.Types.STRUCT:
    case java.sql.Types.VARCHAR:
    default:
        return vf.createLiteral(str);
    }
}

From source file:org.apps8os.motivator.ui.MoodHistoryActivity.java

/** Called when the activity is first created. */
@Override/*from  ww  w.  j a  v  a 2 s  .  c o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mood_history);
    mDayDataHandler = new DayDataHandler(this);

    mCurrentSprint = getIntent().getExtras().getParcelable(Sprint.CURRENT_SPRINT);
    mRes = getResources();
    mSprintStartDateInMillis = mCurrentSprint.getStartTime();
    mSprintEndDateInMillis = mCurrentSprint.getEndTime();

    mDaysInSprint = mCurrentSprint.getDaysInSprint();
    ActionBar actionBar = getActionBar();

    Calendar mToday = Calendar.getInstance();
    UtilityMethods.setToDayStart(mToday);
    mToday.setFirstDayOfWeek(Calendar.MONDAY);

    mNumberOfTodayInSprint = mCurrentSprint.getCurrentDayOfTheSprint();

    // Check if the sprint is already over.
    if (mNumberOfTodayInSprint > mDaysInSprint) {
        mNumberOfTodayInSprint = mDaysInSprint;
    }
    actionBar.setSubtitle(mCurrentSprint.getSprintTitle());
    actionBar.setTitle(mNumberOfTodayInSprint + " " + getString(R.string.days));
    actionBar.setBackgroundDrawable(mRes.getDrawable(R.drawable.action_bar_orange));

    mStartDate = Calendar.getInstance();
    mStartDate.setFirstDayOfWeek(Calendar.MONDAY);
    mStartDate.setTimeInMillis(mSprintStartDateInMillis);

    // Calculate the number of weeks in the sprint
    mNumberOfWeeksInSprint = mToday.get(Calendar.WEEK_OF_YEAR) - mStartDate.get(Calendar.WEEK_OF_YEAR) + 1;
    if (mNumberOfWeeksInSprint < 0) {
        mNumberOfWeeksInSprint = 52 + 1 - mStartDate.get(Calendar.WEEK_OF_YEAR)
                + mToday.get(Calendar.WEEK_OF_YEAR);
    } else {

    }

    // Sets the default selections as today or this week.
    mSelectedDay = mNumberOfTodayInSprint - 1;
    mSelectedWeek = mNumberOfWeeksInSprint - 1;
    mViewPager = (ViewPager) findViewById(R.id.activity_mood_history_viewpager);

    titleIndicator = (TitlePageIndicator) findViewById(R.id.indicator);

    // Page change listener to keep the selected week and day in a member.
    titleIndicator.setOnPageChangeListener(new OnPageChangeListener() {
        @Override
        public void onPageScrollStateChanged(int arg0) {
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageSelected(int arg0) {
            if (mRes.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
                mSelectedDay = arg0;
            } else if (mRes.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
                mSelectedWeek = arg0;
                MoodHistoryWeekFragment fragment = mPagerAdapterWeek.getWeekFragment(arg0);
                if (fragment != null) {
                    fragment.updateSelectedAttribute(mSelectedAttribute, false);
                }
            }
        }
    });

    setPageTitles();

    // Load correct layout and functionality based on orientation
    if (mRes.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        loadPortraitView();
    } else if (mRes.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        loadLandscapeView();
    }

}

From source file:org.davidmendoza.esu.service.impl.InicioServiceImpl.java

@Cacheable(value = "inicioCache")
@Transactional(readOnly = true)//from  w  w  w  .ja  v a2  s  . c o  m
@Override
public Inicio inicio(Inicio inicio) {
    Integer anio = new Integer(inicio.getAnio());
    String trimestre = inicio.getTrimestre();
    String leccion = inicio.getLeccion();
    String dia = inicio.getDia();
    if (StringUtils.isBlank(dia)) {
        dia = obtieneDia(new GregorianCalendar(Locale.ENGLISH).get(Calendar.DAY_OF_WEEK));
        inicio.setDia(dia);
    }
    log.debug("DIA: {}", dia);

    Publicacion leccion1 = publicacionService.obtiene(anio, trimestre, leccion, dia, "leccion");

    Publicacion versiculo = publicacionService.obtiene(anio, trimestre, leccion, null, "versiculo");

    Publicacion video = publicacionService.obtiene(anio, trimestre, leccion, null, "video");

    Publicacion podcast = publicacionService.obtiene(anio, trimestre, leccion, null, "podcast");

    List<Publicacion> dialoga = publicacionService.obtiene(anio, trimestre, leccion, "dialoga");

    List<Publicacion> comunica = publicacionService.obtiene(anio, trimestre, leccion, "comunica");

    PageRequest page = new PageRequest(0, 10, Sort.Direction.ASC, "id");

    List<Publicacion> populares = publicacionService.populares(page);

    Trimestre t = trimestreService.obtiene(anio + trimestre);
    if (t != null) {
        try {
            Calendar cal = new GregorianCalendar(Locale.ENGLISH);
            cal.setTime(t.getInicia());
            cal.add(Calendar.SECOND, 1);
            cal.set(Calendar.DAY_OF_WEEK, obtieneDia(dia));
            int weeks = ((Long) nf.parse(leccion.substring(1))).intValue();
            if (dia.equals("sabado")) {
                weeks--;
            }
            cal.add(Calendar.WEEK_OF_YEAR, weeks);
            Date hoy = cal.getTime();

            inicio.setPublicacion(leccion1);
            inicio.setDialoga(dialoga);
            inicio.setComunica(comunica);
            inicio.setVideo(video);
            inicio.setPodcast(podcast);
            inicio.setVersiculo(versiculo);
            inicio.setHoy(hoy);
            int max = Math.max(dialoga.size(), comunica.size());
            List<Publicacion> articulos = new ArrayList<>();
            for (int i = 0; i < max; i++) {
                if (i < dialoga.size()) {
                    articulos.add(dialoga.get(i));
                }
                if (i < comunica.size()) {
                    articulos.add(comunica.get(i));
                }
            }
            articulos.addAll(populares);
            inicio.setArticulos(articulos);

            return inicio;
        } catch (ParseException e) {
            log.error("No pude poner la fecha de hoy", e);
        }
    }

    return null;
}

From source file:edu.wisc.my.stats.query.support.UWDataWareHouseInformationProvider.java

public long getTimeStamp(ResultSet rs, TimeResolution resolution) throws SQLException {
    final Calendar timeStampCal = Calendar.getInstance();
    timeStampCal.clear();/*from   w  w  w .ja va  2s. c  o  m*/

    switch (resolution) {
    case MINUTE:
        final int minutes = rs.getInt("MINUTE");
        timeStampCal.set(Calendar.MINUTE, minutes);
    case FIVE_MINUTE:
        if (!timeStampCal.isSet(Calendar.MINUTE)) {
            final int fiveMinutes = rs.getInt("FIVE_MINUTE_INCREMENT");
            timeStampCal.set(Calendar.MINUTE, (fiveMinutes - 1) * 5);
        }
    case HOUR:
        final int hours = rs.getInt("HOUR");
        timeStampCal.set(Calendar.HOUR, hours);
    case DAY:
        final int days = rs.getInt("CALENDAR_DAY_NUMBER");
        timeStampCal.set(Calendar.DAY_OF_MONTH, days);
    case WEEK:
        final int week = rs.getInt("CALENDAR_WEEK_NUMBER");
        timeStampCal.set(Calendar.WEEK_OF_YEAR, week);
    case MONTH:
        final int months = rs.getInt("CALENDAR_MONTH_NUMBER");
        timeStampCal.set(Calendar.MONTH, months - 1); //Dang 0 based months
    case YEAR:
        final int years = rs.getInt("CALENDAR_YEAR_NUMBER");
        timeStampCal.set(Calendar.YEAR, years);
    }

    return timeStampCal.getTimeInMillis();
}