Example usage for java.util Calendar setTimeInMillis

List of usage examples for java.util Calendar setTimeInMillis

Introduction

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

Prototype

public void setTimeInMillis(long millis) 

Source Link

Document

Sets this Calendar's current time from the given long value.

Usage

From source file:py.una.pol.karaku.test.test.dao.clauses.DateClausesTest.java

private Date newTime(int day, int month, int year, int hours, int minutes) {

    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(0);
    c.set(Calendar.DAY_OF_MONTH, day);
    c.set(Calendar.MONTH, month);
    c.set(Calendar.YEAR, year);/*from w  w w. j av  a 2 s .  c  o m*/
    c.set(Calendar.HOUR_OF_DAY, hours);
    c.set(Calendar.MINUTE, minutes);

    return c.getTime();
}

From source file:de.uzk.hki.da.metadata.PremisXmlReaderTests.java

/**
 * Test rights./*from ww w.  j a  v a  2 s  . com*/
 *
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws ParseException
 *             the parse exception
 */
@Test
public void testRights() throws IOException, ParseException {

    ObjectPremisXmlReader reader = new ObjectPremisXmlReader();
    Object premisObject = reader
            .deserialize(new File("src/test/resources/metadata/premis_xml_metadata_reader_test.xml"));

    System.out.println(premisObject.getRights());
    assertNotNull(premisObject.getRights());
    assertNotNull(premisObject.getRights().getPublicationRights());
    assertFalse(premisObject.getRights().getPublicationRights().isEmpty());
    assertEquals("640",
            premisObject.getRights().getPublicationRights().get(0).getImageRestriction().getWidth());
    assertEquals("480",
            premisObject.getRights().getPublicationRights().get(0).getImageRestriction().getHeight());

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(0);
    calendar.set(2023, 5, 23, 0, 0, 0);

    assertEquals(MigrationRight.Condition.NOTIFY, premisObject.getRights().getMigrationRight().getCondition());

    assertEquals("ePflicht", premisObject.getRights().getPublicationRights().get(0).getLawID());
    assertEquals(2, premisObject.getRights().getPublicationRights().get(0).getTextRestriction()
            .getCertainPages().length);
    assertEquals(23,
            premisObject.getRights().getPublicationRights().get(0).getTextRestriction().getCertainPages()[0]);
    assertEquals(42,
            premisObject.getRights().getPublicationRights().get(0).getTextRestriction().getCertainPages()[1]);

    assertTrue(!premisObject.grantsPublicationRight(Audience.PUBLIC));
    assertTrue(!premisObject.grantsPublicationRight(Audience.INSTITUTION));

}

From source file:TPPDekuBot.BattleBot.java

public static void append(String input) {
    Date date = new Date();
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    String outDate = ISO_8601_DATE_TIME.format(date);
    try (BufferedWriter fw = new BufferedWriter(new FileWriter(logFile, true))) {
        fw.append("[" + outDate + "] " + input);
        fw.newLine();/*from  w  w w  .  java 2 s  . c  o m*/
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println("Failed to write! " + ex);
    }
}

From source file:com.adobe.acs.commons.wcm.impl.FileImporterTest.java

@Test
public void testImportToFolderHavingFileWhichIsOlder() throws Exception {
    final Calendar earliest = Calendar.getInstance();
    earliest.setTimeInMillis(0L);
    final Node file = JcrUtils.putFile(folder, testFile.getName(), "x-text/test",
            new ByteArrayInputStream("".getBytes()), earliest);

    session.save();/*from   ww  w  . java2 s. co  m*/

    Resource resource = mock(Resource.class);
    when(resource.adaptTo(Node.class)).thenReturn(folder);
    importer.importData("file", testFile.getAbsolutePath(), resource);

    assertFalse(session.hasPendingChanges());
    assertTrue(folder.hasNode(testFile.getName()));
    assertEquals("text/plain", JcrUtils.getStringProperty(file, "jcr:content/jcr:mimeType", ""));
}

From source file:org.n52.server.sos.generator.DiagramGenerator.java

/**
 * Creates a time series chart diagram and writes it to the OutputStream.
 * /*from   ww w.ja v  a  2 s .  co m*/
 * @param entireCollMap
 * @param options
 * @param out
 * @throws OXFException
 * @throws IOException
 */
public void producePresentation(Map<String, OXFFeatureCollection> entireCollMap, DesignOptions options,
        FileOutputStream out, boolean compress) throws OXFException, IOException {

    // render features:
    int width = options.getWidth();
    int height = options.getHeight();
    Calendar begin = Calendar.getInstance();
    begin.setTimeInMillis(options.getBegin());
    Calendar end = Calendar.getInstance();
    end.setTimeInMillis(options.getEnd());

    DiagramRenderer renderer = new DiagramRenderer(false);

    JFreeChart diagramChart = renderer.renderChart(entireCollMap, options, begin, end, compress);
    diagramChart.removeLegend();

    // draw chart into image:
    BufferedImage diagramImage = new BufferedImage(width, height, TYPE_INT_RGB);
    Graphics2D chartGraphics = diagramImage.createGraphics();
    chartGraphics.setColor(Color.white);
    chartGraphics.fillRect(0, 0, width, height);

    diagramChart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height));

    JPEGEncodeParam p = new JPEGEncodeParam();
    p.setQuality(1f);
    ImageEncoder encoder = ImageCodec.createImageEncoder("jpeg", out, p);

    encoder.encode(diagramImage);
}

From source file:eu.dime.ps.dto.Profile.java

public PersonContact asResource(URI resourceUri, URI me) {
    Model rModel = RDF2Go.getModelFactory().createModel().open();
    PersonContact result = new PersonContact(rModel, resourceUri, true);

    this.remove("userId");
    this.remove("said");
    this.remove("editable");

    for (String key : keySet()) {
        if (key.equals("guid") || key.equals("items")) {
            continue;
        }/*from w  ww  .j  a  v  a 2s.c o m*/

        if (!(get(key) == null || "".equals(get(key)))) {

            if (key.equals("created")) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis((Long) get(key));
                rModel.addStatement(resourceUri, NAO.created, RDFReactorRuntime.java2node(rModel, calendar));
            } else if (key.equals("lastModified")) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis((Long) get(key));
                rModel.addStatement(resourceUri, NAO.lastModified,
                        RDFReactorRuntime.java2node(rModel, calendar));
            } else if (key.equals("name")) {
                rModel.addStatement(resourceUri, NAO.prefLabel, new PlainLiteralImpl((String) get(key)));
            } else if (key.equals("imageUrl")) {
                rModel.addStatement(resourceUri, NAO.prefSymbol, new URIImpl((String) get(key)));
            }
        }
    }

    return result;
}

From source file:com.QuarkLabs.BTCeClientJavaFX.PublicTradesController.java

@FXML
void initialize() {
    assert publicTradesTable != null : "fx:id=\"publicTradesTable\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTableAmountColumn != null : "fx:id=\"publicTradesTableAmountColumn\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTableDateColumn != null : "fx:id=\"publicTradesTableDateColumn\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTableItemColumn != null : "fx:id=\"publicTradesTableItemColumn\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTablePriceColumn != null : "fx:id=\"publicTradesTablePriceColumn\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTablePriceCurrencyColumn != null : "fx:id=\"publicTradesTablePriceCurrencyColumn\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTableTIDColumn != null : "fx:id=\"publicTradesTableTIDColumn\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTableTradeTypeColumn != null : "fx:id=\"publicTradesTableTradeTypeColumn\" was not injected: check your FXML file 'markettrades.fxml'.";

    publicTradesTable.setItems(publicTrades);
    publicTradesTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    publicTradesTableAmountColumn.setCellValueFactory(new PropertyValueFactory<PublicTrade, Double>("amount"));
    publicTradesTableDateColumn.setCellValueFactory(
            new Callback<TableColumn.CellDataFeatures<PublicTrade, String>, ObservableValue<String>>() {
                @Override//from   w w w . ja v  a  2s  .c  om
                public ObservableValue<String> call(
                        TableColumn.CellDataFeatures<PublicTrade, String> publicTradeStringCellDataFeatures) {
                    PublicTrade publicTrade = publicTradeStringCellDataFeatures.getValue();
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTimeInMillis(publicTrade.getDate() * 1000);
                    DateFormat dateFormat = DateFormat.getDateTimeInstance();
                    return new SimpleStringProperty(dateFormat.format(calendar.getTime()));
                }
            });
    publicTradesTableItemColumn.setCellValueFactory(new PropertyValueFactory<PublicTrade, String>("item"));
    publicTradesTablePriceColumn.setCellValueFactory(new PropertyValueFactory<PublicTrade, Double>("price"));
    publicTradesTablePriceCurrencyColumn
            .setCellValueFactory(new PropertyValueFactory<PublicTrade, String>("priceCurrency"));
    publicTradesTableTIDColumn.setCellValueFactory(new PropertyValueFactory<PublicTrade, Long>("tid"));
    publicTradesTableTradeTypeColumn
            .setCellValueFactory(new PropertyValueFactory<PublicTrade, String>("tradeType"));

    Task<JSONArray> loadPublicTrades = new Task<JSONArray>() {
        @Override
        protected JSONArray call() throws Exception {
            return App.getPublicTrades(pair);
        }
    };
    loadPublicTrades.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent workerStateEvent) {
            JSONArray jsonArray = (JSONArray) workerStateEvent.getSource().getValue();
            publicTrades.clear();
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject item = jsonArray.getJSONObject(i);
                PublicTrade publicTrade = new PublicTrade();
                publicTrade.setDate(item.getLong("date"));
                publicTrade.setAmount(item.getDouble("amount"));
                publicTrade.setItem(item.getString("item"));
                publicTrade.setPrice(item.getDouble("price"));
                publicTrade.setPriceCurrency(item.getString("price_currency"));
                publicTrade.setTid(item.getLong("tid"));
                publicTrade.setTradeType(item.getString("trade_type"));
                publicTrades.add(publicTrade);
            }
        }
    });
    Thread thread = new Thread(loadPublicTrades);
    thread.start();
}

From source file:com.aremaitch.codestock2010.datadownloader.DownloaderV2.java

private Calendar convertToCalendar(String dateString) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(Long.parseLong(dateString.substring(6, 19)));
    cal.setTimeZone(TimeZone.getTimeZone("GMT" + dateString.substring(19, 24)));
    return cal;/* ww w.j ava 2  s  . co m*/
}

From source file:de.micmun.android.workdaystarget.DayCalculator.java

/**
 * Returns the number of days between today and target, skipped days in
 * appliance of checkedDays./*from w  w w .  j a v a 2 s . co m*/
 *
 * @param t           Date of the target, to which to calculate the working days.
 * @param checkedDays Array with boolean flags, which says if a weekday should count
 *                    or not.
 * @return days to target.
 * @throws JSONException if an error occurs while getting the holidays from web service.
 */
public int getDaysLeft(Date t, boolean[] checkedDays) throws JSONException {
    // sets target time at midnight
    target.setTime(t);
    setMidnight(target);

    int sign = 1;

    if (target.getTimeInMillis() < today.getTimeInMillis()) {
        Calendar tmp = Calendar.getInstance();
        tmp.setTimeInMillis(target.getTimeInMillis());
        target.setTimeInMillis(today.getTimeInMillis());
        today.setTimeInMillis(tmp.getTimeInMillis());
        sign = -1; // negative days in the past
    }

    // Holidays
    ArrayList<Date> holidays = getHolidays();

    // current time
    Calendar curr = Calendar.getInstance();
    curr.setTime(today.getTime());

    int count = 0;

    while (curr.getTimeInMillis() != target.getTimeInMillis()) {
        curr.add(Calendar.DAY_OF_MONTH, 1);
        int dayOfWeek = curr.get(Calendar.DAY_OF_WEEK);

        if (!checkedDays[POS_HOLIDAY] && holidays.contains(curr.getTime())) {
            continue;
        } else if (!checkedDays[POS_SUNDAY] && dayOfWeek == Calendar.SUNDAY) {
            continue;
        } else if (dayOfWeek != Calendar.SUNDAY && !checkedDays[dayOfWeek - Calendar.MONDAY]) {
            continue;
        }
        count++;
    }

    count *= sign; // if target is in the past, sign == -1

    return count;
}

From source file:net.java.dev.weblets.impl.servlets.WebletResponseImpl.java

/**
 * y2038k fix for certain servers (aka WAS 6.1)
 *
 * @param timeout the incoming time value to be fixed
 * @return/*from   ww  w .jav a2s. com*/
 */
private long y2038k_fix(long timeout) {
    java.util.Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(timeout);
    if (cal.get(Calendar.YEAR) >= Y2038_BOUNDARY) {
        cal.set(Calendar.YEAR, Y0238_VALIDYEAR);
    }
    return cal.getTimeInMillis();
}