Example usage for org.joda.time DateTimeZone UTC

List of usage examples for org.joda.time DateTimeZone UTC

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone UTC.

Prototype

DateTimeZone UTC

To view the source code for org.joda.time DateTimeZone UTC.

Click Source Link

Document

The time zone for Universal Coordinated Time

Usage

From source file:com.eldar.models.Base.java

License:Open Source License

public Base() {
    setCreatedDate(DateTime.now(DateTimeZone.UTC));
    setModifiedDate(getCreatedDate());
}

From source file:com.eldar.services.ResourceService.java

License:Open Source License

private String getFileName(String name, int version) {
    return name + "_" + version + "_" + DateTime.now(DateTimeZone.UTC).toString("yyyy-MM-dd-HH-mm-ss");
}

From source file:com.enitalk.configs.DateCache.java

@Bean(name = "skipCache")
public LoadingCache<String, ConcurrentSkipListSet<DateTime>> datesMap() {
    CacheBuilder<Object, Object> ccc = CacheBuilder.newBuilder();
    ccc.expireAfterWrite(2, TimeUnit.MINUTES);

    LoadingCache<String, ConcurrentSkipListSet<DateTime>> cache = ccc
            .build(new CacheLoader<String, ConcurrentSkipListSet<DateTime>>() {

                @Override/*  w  w w. ja v a2s. c  om*/
                public ConcurrentSkipListSet<DateTime> load(String key) throws Exception {
                    try {
                        HashMap teachers = mongo.findOne(Query.query(Criteria.where("i").is(key)),
                                HashMap.class, "teachers");
                        ObjectNode teacherJson = jackson.convertValue(teachers, ObjectNode.class);
                        String timeZone = teacherJson.at("/calendar/timeZone").asText();

                        NavigableSet<DateTime> set = days(teacherJson.path("schedule"), timeZone, teacherJson);

                        DateTimeZone dzz = DateTimeZone.forID(timeZone);
                        DateTimeFormatter df = ISODateTimeFormat.dateTimeNoMillis().withZone(dzz);

                        byte[] events = calendar.busyEvents(jackson.createObjectNode().put("id", key));
                        JsonNode evs = jackson.readTree(events);
                        Iterator<JsonNode> its = evs.iterator();
                        TreeSet<DateTime> dates = new TreeSet<>();
                        while (its.hasNext()) {
                            String date = its.next().asText();
                            DateTime av = df.parseDateTime(date).toDateTime(DateTimeZone.UTC);
                            dates.add(av);
                        }

                        set.removeAll(dates);

                        logger.info("Dates for i {} {}", key, set);

                        return new ConcurrentSkipListSet<>(set);

                    } catch (Exception e) {
                        logger.error(ExceptionUtils.getFullStackTrace(e));
                    }
                    return null;
                }

            });

    return cache;
}

From source file:com.enitalk.configs.DateCache.java

public NavigableSet<DateTime> days(JsonNode tree, String tz, JsonNode teacherNode) {
    ConcurrentSkipListSet<DateTime> dates = new ConcurrentSkipListSet<>();

    Iterator<JsonNode> els = tree.elements();
    DateTimeZone dz = DateTimeZone.forID(tz);
    DateTimeFormatter hour = DateTimeFormat.forPattern("HH:mm").withZone(dz);

    DateTime today = DateTime.now().millisOfDay().setCopy(0);
    while (els.hasNext()) {

        JsonNode el = els.next();/*from w w  w  .j  a  v  a 2 s. com*/
        String day = el.path("day").asText();

        boolean plus = today.getDayOfWeek() > days.get(day);
        if (el.has("start") && el.has("end")) {
            DateTime start = hour.parseDateTime(el.path("start").asText()).dayOfMonth()
                    .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year()
                    .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);
            DateTime end = hour.parseDateTime(el.path("end").asText()).dayOfMonth()
                    .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year()
                    .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);

            Hours hours = Hours.hoursBetween(start, end);
            int hh = hours.getHours() + 1;

            while (hh-- > 0) {
                dates.add(start.plusHours(hh).toDateTime(DateTimeZone.UTC));
            }
        } else {
            List<String> datesAv = jackson.convertValue(el.path("times"), List.class);
            logger.info("Array of dates {} {}", datesAv, day);

            datesAv.forEach((String dd) -> {
                DateTime date = hour.parseDateTime(dd).dayOfMonth().setCopy(today.getDayOfMonth()).monthOfYear()
                        .setCopy(today.getMonthOfYear()).year().setCopy(today.getYear())
                        .withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);
                dates.add(date.toDateTime(DateTimeZone.UTC));
            });

        }

    }

    final TreeSet<DateTime> addWeek = new TreeSet<>();
    for (int i = 1; i < 2; i++) {
        for (DateTime e : dates) {
            addWeek.add(e.plusWeeks(i));

        }
    }

    dates.addAll(addWeek);

    DateTime nowUtc = DateTime.now().toDateTime(DateTimeZone.UTC);
    nowUtc = nowUtc.plusHours(teacherNode.path("notice").asInt(2));

    NavigableSet<DateTime> ss = dates.tailSet(nowUtc, true);

    return ss;

}

From source file:com.enitalk.controllers.bots.TimeZoneTestr.java

public static void main(String[] args) {
    Set<String> ids = DateTimeZone.getAvailableIDs();
    TreeMultimap<Long, String> map = TreeMultimap.create();
    for (String id : ids) {
        DateTimeZone dz = DateTimeZone.forID(id);
        int offset = dz.getOffset(DateTime.now().withZone(DateTimeZone.UTC));

        map.put(TimeUnit.MILLISECONDS.toMinutes(offset), id);
    }/*ww  w  .  ja  va2s  . co  m*/

    ObjectMapper j = new ObjectMapper();
    ArrayNode a = j.createArrayNode();
    map.keySet().forEach((Long key) -> {
        a.addObject().set(key.toString(), j.convertValue(map.get(key), ArrayNode.class));
    });

    System.out.println(a);

    //        System.out.println(map);
}

From source file:com.enitalk.controllers.OpentokSessionController.java

@RequestMapping(method = RequestMethod.GET, value = "/session/teacher/{id}", produces = "text/html")
@ResponseBody//from   w ww.j a  v  a2  s  .  com
public byte[] sessionTeacher(@PathVariable String id, HttpServletResponse res, boolean requireUrl)
        throws IOException {
    byte[] out = null;
    try {
        Query q = Query.query(Criteria.where("ii").is(id).andOperator(Criteria.where("status").is(2)));
        logger.info("Looking for teacher event {}", id);
        HashMap ev = mongo.findOne(q, HashMap.class, "events");
        if (ev == null) {
            return "Sorry, no such event found.".getBytes();
        }

        Date date = (Date) ev.get("dd");
        DateTime scheduled = new DateTime(date.getTime()).toDateTime(DateTimeZone.UTC);
        DateTime nnow = new DateTime(DateTimeZone.UTC);
        int bt = Minutes.minutesBetween(nnow, scheduled).getMinutes();

        logger.info("Scheduled joda {} diff {}", scheduled, bt);

        ObjectNode evJson = jackson.convertValue(ev, ObjectNode.class);

        if (bt > 6) {
            String rs = "You're a bit early, please visit this page at "
                    + scheduled.minusMinutes(5).toString("yyyy/MM/dd HH:mm:ss 'GMT'");
            return rs.getBytes();
        }
        //            
        if (bt < -62) {
            String rs = "It seems that your session has already ended or expired. Please, contact us at ceo@enitalk.com if there seems to be a mistake.";
            return rs.getBytes();
        }

        String url = s3Cache.get(evJson);

        if (!requireUrl) {
            url += "?dest=" + evJson.at("/ii").asText() + "&i=" + evJson.path("ii").asText();
            String signed = signer.signUrl(url, new DateTime().plusMinutes(80));
            res.sendRedirect(signed);
        } else {
            return url.getBytes();
        }
    } catch (Exception e) {
        logger.error(ExceptionUtils.getFullStackTrace(e));
        return "Oops. Something went wrong. Contact us at ceo@enitalk.com".getBytes();
    }
    return out;
}

From source file:com.enitalk.controllers.youtube.processor.Y2BeProcessor.java

public void run() {
    try {//w w w . j a va  2s .co m
        logger.info("Running processor");

        //TO-DO make it work only for 30+ minutes after the 
        Query q = Query.query(Criteria.where("").is(""));
        List<HashMap> items = mongo.find(q, HashMap.class, "events");
        ArrayNode its = jackson.convertValue(items, ArrayNode.class);

        final List<JsonNode> allEvents = its.findParents("ii");

        allEvents.forEach((JsonNode el) -> {
            try {

                List<String> ids = jackson.convertValue(el.path("liveId"), List.class);
                Credential credential = flow.loadCredential(el.at("/teacher/dest/sendTo").toString());
                YouTube youtube = new YouTube.Builder(new NetHttpTransport(),
                        JacksonFactory.getDefaultInstance(), credential).setApplicationName("enitalk").build();
                boolean refreshed = credential.refreshToken();
                logger.info("Token refreshed {} id {}", refreshed);

                YouTube.Videos.List list = youtube.videos()
                        .list("id,liveStreamingDetails,recordingDetails,status,statistics");
                list.setId(StringUtils.join(ids, ','));
                logger.info("Video param query {}", list.buildHttpRequestUrl());

                byte[] response = IOUtils.toByteArray(list.executeUnparsed().getContent());

                JsonNode r = jackson.readTree(response);
                logger.info("Yt response {}", r);
                Update u = new Update().set("records", jackson.convertValue(r, HashMap.class));

                long finishedItems = r.path("items").findParents("id").stream().filter((JsonNode yt) -> {
                    return yt.at("/status/uploadStatus").asText().equals("processed");
                }).count();

                logger.info("Finished items {}", finishedItems);

                if (finishedItems == ids.size()) {
                    logger.info("All items finished, shall sent links to user");

                } else {
                    u.set("nextCheck", new DateTime(DateTimeZone.UTC).plusMinutes(15).toDate());
                }

                mongo.updateFirst(Query.query(Criteria.where("ii").is(el.path("ii").asText())), u, "events");

            } catch (Exception e) {
                logger.error(ExceptionUtils.getFullStackTrace(e));
            }

        });

    } catch (Exception e) {
        logger.error(ExceptionUtils.getFullStackTrace(e));
    }
}

From source file:com.enonic.cms.business.timezone.TimeZoneServiceImpl.java

License:Open Source License

@SuppressWarnings({ "unchecked" })
public void afterPropertiesSet() throws Exception {
    Set<String> ids = DateTimeZone.getAvailableIDs();
    timeZones.add(DateTimeZone.UTC);
    for (String id : ids) {
        if (!id.equals("UTC")) {
            timeZones.add(DateTimeZone.forID(id));
        }/*from   w ww  . j  av a2  s.  c o m*/
    }
}

From source file:com.enonic.cms.core.search.ElasticSearchFormatter.java

License:Open Source License

public static ReadableDateTime toUTCTimeZone(final ReadableDateTime dateTime) {
    if (DateTimeZone.UTC.equals(dateTime.getZone())) {
        return dateTime;
    }/*from w  ww  . j  a  v a 2 s  . c o m*/
    final MutableDateTime dateInUTC = dateTime.toMutableDateTime();
    dateInUTC.setZone(DateTimeZone.UTC);
    return dateInUTC.toDateTime();
}

From source file:com.enonic.cms.core.search.query.factory.FilterQueryBuilderFactory.java

License:Open Source License

private ReadableDateTime toUTCTimeZone(final ReadableDateTime dateTime) {
    if (DateTimeZone.UTC.equals(dateTime.getZone())) {
        return dateTime;
    }/* w  w w.j  a  v  a2s .  co  m*/
    final MutableDateTime dateInUTC = dateTime.toMutableDateTime();
    dateInUTC.setZone(DateTimeZone.UTC);
    return dateInUTC.toDateTime();
}