当前位置: 首页>>代码示例>>Java>>正文


Java ZonedDateTime.plusMinutes方法代码示例

本文整理汇总了Java中java.time.ZonedDateTime.plusMinutes方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.plusMinutes方法的具体用法?Java ZonedDateTime.plusMinutes怎么用?Java ZonedDateTime.plusMinutes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.ZonedDateTime的用法示例。


在下文中一共展示了ZonedDateTime.plusMinutes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSelectWithParallelProcessing

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test()
public void testSelectWithParallelProcessing() {
    final ZonedDateTime start = ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.of("GMT"));
    final ZonedDateTime end = start.plusMinutes(1000000);
    final Duration step = Duration.ofMinutes(1);
    final Index<ZonedDateTime> colKeys = Range.of(start, end, step).toIndex(ZonedDateTime.class);
    final DataFrame<String,ZonedDateTime> frame = DataFrame.of("C", colKeys, Double.class).applyDoubles(v -> Math.random() * 100);
    final long expectedCount = colKeys.keys().filter(t -> t.getDayOfWeek() == DayOfWeek.MONDAY).count();
    final DataFrame<String,ZonedDateTime> select1 = frame.cols().parallel().select(col -> col.key().getDayOfWeek() == DayOfWeek.MONDAY);
    final DataFrame<String,ZonedDateTime> select2 = frame.cols().sequential().select(col -> col.key().getDayOfWeek() == DayOfWeek.MONDAY);
    Assert.assertEquals(select1.colCount(), expectedCount, "Selection 1 has expected column count");
    Assert.assertEquals(select2.colCount(), expectedCount, "Selection 1 has expected column count");
    Assert.assertEquals(select1.rowCount(), 1, "Selection 1 has expected row count");
    Assert.assertEquals(select2.rowCount(), 1, "Selection 1 has expected row count");
    DataFrameAsserts.assertEqualsByIndex(select1, select2);
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:17,代码来源:ColumnTests.java

示例2: test_plusMinutes_minutes

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_plusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), ZONE_0100));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKZonedDateTime.java

示例3: parseTimeString

import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
 * evaluates a announcement override 'time string' into a definite ZonedDateTime object
 * @param time 'time string'
 * @param se ScheduleEntry the override resides on
 * @return ZonedDateTime for announcement override, or null if un-parsable
 */
public static ZonedDateTime parseTimeString(String time, ScheduleEntry se)
{
    time = time.toUpperCase();  // all caps

    // determine basis for the announcement time
    ZonedDateTime announcementTime;
    if(time.startsWith("START"))
    {
        time = time.replace("START", "");
        announcementTime = se.getStart();
    }
    else if(time.startsWith("END"))
    {
        time = time.replace("END", "");
        announcementTime = se.getEnd();
    }
    else
    {
        return null;
    }

    // determine if offset is positive or negative
    boolean positive;
    if(time.startsWith("+"))
    {
        time = time.replace("+", "");
        positive = true;
    }
    else if(time.startsWith("-"))
    {
        time = time.replace("-", "");
        positive = false;
    }
    else
    {
        return announcementTime;
    }

    // parse out the time offset
    Integer minutes = time.replaceAll("[^\\d]", "").isEmpty() ?
            0 : Integer.parseInt(time.replaceAll("[^\\d]", ""));
    if (minutes != 0)
    {
        switch(time.charAt(time.length()-1))
        {
            case 'H':
                minutes = minutes*60;
                break;
            case 'D':
                minutes = 60*24;
                break;
        }
    }

    // add offset to the time and return
    if(positive) return announcementTime.plusMinutes(minutes);
    else return announcementTime.minusMinutes(minutes);
}
 
开发者ID:notem,项目名称:Saber-Bot,代码行数:65,代码来源:ParsingUtilities.java

示例4: schedule

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public void schedule(Job job) throws Exception {
  logger.info("Start={}:{}, period={} minutes, job={}", String.format("%02d", hourOfDay),
    String.format("%02d", minuteOfHour), period, job.getClass().getName());

  ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC).withSecond(0).withNano(0);
  ZonedDateTime start = now.withHour(hourOfDay).withMinute(minuteOfHour).withSecond(0).withNano(0);
  while (start.isBefore(now)) {
    start = start.plusMinutes(period);
  }

  long initialDelay = ChronoUnit.MINUTES.between(now, start);
  next = start;
  logger.info("Starting job execution in {} minutes at {}.", initialDelay, next);

  ScheduledFuture sfuture = null;
  ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
  Runnable jobRunner = () -> {
    runCounter++;
    next = next.plusMinutes(period);
    logger.info(">>>>>>>>>> Starting job execution #{} on {}.", runCounter, job.getClass().getName());
    try {
      job.execute();
    } catch (Exception e) {
      errorCounter++;
      logger.error("Premature end of job execution #{}. error count={}", runCounter, errorCounter, e);
      if (errorCounter >= maxErrorCount) {
        logger.info("Stopping application because errorCount >= {}", maxErrorCount);
        System.exit(-1);
      }
    }
    logger.info("<<<<<<<<<< End of job execution #{} on {}", runCounter, job.getClass().getName());
    if (stop) {
      logger.info("Stopped application at synchronisation run #{}, because file named 'cfg/stop' was found.",
        runCounter);
    } else {
      logger.info("delay={}", scheduledFuture.getDelay(TimeUnit.MINUTES));
      logger.info("# touch cfg/stop # - to stop this service gracefully.");
      // in case execution takes longer then period, adjust next
      ZonedDateTime rightnow = ZonedDateTime.now(ZoneOffset.UTC).withSecond(0).withNano(0);
      if (next.isBefore(rightnow)) {
        long excess = ChronoUnit.MINUTES.between(next, rightnow);
        logger.warn("Job execution takes longer then period. Job execution exceeds {}-minute period with {} minutes.",
          period, excess);
      }
      //
      logger.info("Next job execution planned at {}", next);
    }
  };
  scheduledFuture = scheduler.scheduleAtFixedRate(jobRunner, initialDelay, period, TimeUnit.MINUTES);

  // Watch the file system for a file named 'stop'
  ScheduledExecutorService watch = Executors.newScheduledThreadPool(1);
  Runnable watcher = () -> {
    if (new File("cfg/stop").exists()) {
      stop = true;
      logger.info("Stopping scheduler after job execution #{}, because file named 'cfg/stop' was found.",
        runCounter);
      scheduler.shutdown();
      watch.shutdown();
    }
  };

  watch.scheduleWithFixedDelay(watcher, 0, 1, TimeUnit.SECONDS);
}
 
开发者ID:EHRI,项目名称:rs-aggregator,代码行数:66,代码来源:RunAtFixedRate.java

示例5: executeBan

import java.time.ZonedDateTime; //导入方法依赖的package包/类
public boolean executeBan(String name, String uuid, String[] args, String banner, Player banned) {
    if (!PunishmentManager.ips_byUUID.containsKey(uuid))
        return false;
    String ip = PunishmentManager.ips_byUUID.get(uuid);
    String time = args[1].toLowerCase();
    ZonedDateTime endTime = ZonedDateTime.now();
    String lengthDisplay = "";
    if (args[1].startsWith("perm")) {
        endTime = endTime.plusYears(1000);
        lengthDisplay = ChatColor.YELLOW + "permanently" + ChatColor.RED + " IP banned";
    } else {
        int amount = Integer.parseInt(time.replaceAll("[^0-9]", ""));
        if (time.endsWith("m")) {
            endTime = endTime.plusMinutes(amount);
            lengthDisplay = "IP banned for " + ChatColor.YELLOW + amount + " minute" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("h")) {
            endTime = endTime.plusHours(amount);
            lengthDisplay = "IP banned for " + ChatColor.YELLOW + amount + " hour" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("d")) {
            endTime = endTime.plusDays(amount);
            lengthDisplay = "IP banned for " + ChatColor.YELLOW + amount + " day" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("w")) {
            endTime = endTime.plusWeeks(amount);
            lengthDisplay = "IP banned for " + ChatColor.YELLOW + amount + " week" + (amount != 1 ? "s" : "");
        } else {
            return false;
        }
    }
    lengthDisplay += ChatColor.RESET;
    StringBuilder sb = new StringBuilder();
    for (int k = 2; k < args.length; k++) {
        sb.append(args[k]);
        sb.append(' ');
    }
    final ZonedDateTime fEndTime = endTime;
    String reason = sb.toString().trim();
    RScheduler.scheduleAsync(plugin, () -> {
        AutoCloseable[] ac_dub2 = SQLManager.prepare("INSERT INTO punishments (name, uuid, ip, type, endTime, reason, giver, startTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ");
        PreparedStatement insert_ban = (PreparedStatement) ac_dub2[0];
        try {
            insert_ban.setString(1, name);
            insert_ban.setString(2, uuid);
            insert_ban.setString(3, ip);
            insert_ban.setString(4, PunishmentType.IPBAN.toString());
            insert_ban.setString(5, fEndTime.toString());
            insert_ban.setString(6, reason);
            insert_ban.setString(7, banner);
            insert_ban.setString(8, ZonedDateTime.now().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        SQLManager.execute(ac_dub2);
        SQLManager.close(ac_dub2);
        System.out.println("Executed IP ban for " + name + ".");
    });
    String announce = ChatColor.YELLOW + name + ChatColor.RED + " was " + lengthDisplay + ChatColor.RED + " by " + ChatColor.YELLOW + banner + ChatColor.RED + " for: " + ChatColor.WHITE + ChatColor.BOLD + reason + ChatColor.RED + ".";
    RMessages.announce(ChatColor.GRAY + "> " + announce);
    if (banned != null && banned.isOnline())
        banned.kickPlayer("You were " + lengthDisplay + " by " + banner + " for: " + reason + ".");
    return true;
}
 
开发者ID:edasaki,项目名称:ZentrelaCore,代码行数:62,代码来源:BanIPCommand.java

示例6: executeMute

import java.time.ZonedDateTime; //导入方法依赖的package包/类
public boolean executeMute(String name, String uuid, String[] args, String muter, Player muted) {
    String time = args[1].toLowerCase();
    ZonedDateTime endTime = ZonedDateTime.now();
    String lengthDisplay = "";
    if (args[1].startsWith("perm")) {
        endTime = endTime.plusYears(1000);
        lengthDisplay = ChatColor.YELLOW + "permanently" + ChatColor.RED + " muted";
    } else {
        int amount = Integer.parseInt(time.replaceAll("[^0-9]", ""));
        if (time.endsWith("m")) {
            endTime = endTime.plusMinutes(amount);
            lengthDisplay = "muted for " + ChatColor.YELLOW + amount + " minute" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("h")) {
            endTime = endTime.plusHours(amount);
            lengthDisplay = "muted for " + ChatColor.YELLOW + amount + " hour" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("d")) {
            endTime = endTime.plusDays(amount);
            lengthDisplay = "muted for " + ChatColor.YELLOW + amount + " day" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("w")) {
            endTime = endTime.plusWeeks(amount);
            lengthDisplay = "muted for " + ChatColor.YELLOW + amount + " week" + (amount != 1 ? "s" : "");
        } else {
            return false;
        }
    }
    lengthDisplay += ChatColor.RESET;
    StringBuilder sb = new StringBuilder();
    for (int k = 2; k < args.length; k++) {
        sb.append(args[k]);
        sb.append(' ');
    }
    final ZonedDateTime fEndTime = endTime;
    String reason = sb.toString().trim();
    RScheduler.scheduleAsync(plugin, () -> {
        AutoCloseable[] ac_dub2 = SQLManager.prepare("INSERT INTO punishments (name, uuid, ip, type, endTime, reason, giver, startTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ");
        PreparedStatement insert_mute = (PreparedStatement) ac_dub2[0];
        try {
            insert_mute.setString(1, name);
            insert_mute.setString(2, uuid);
            insert_mute.setString(3, PunishmentManager.ips_byUUID.containsKey(uuid) ? PunishmentManager.ips_byUUID.get(uuid) : "");
            insert_mute.setString(4, PunishmentType.MUTE.toString());
            insert_mute.setString(5, fEndTime.toString());
            insert_mute.setString(6, reason);
            insert_mute.setString(7, muter);
            insert_mute.setString(8, ZonedDateTime.now().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        SQLManager.execute(ac_dub2);
        SQLManager.close(ac_dub2);
        System.out.println("Executed mute for " + name + ".");
        PunishmentManager.checkMute(uuid);
    });
    String announce = ChatColor.YELLOW + name + ChatColor.RED + " was " + lengthDisplay + ChatColor.RED + " by " + ChatColor.YELLOW + muter + ChatColor.RED + " for: " + ChatColor.WHITE + ChatColor.BOLD + reason + ChatColor.RED + ".";
    RMessages.announce(ChatColor.GRAY + "> " + announce);
    return true;
}
 
开发者ID:edasaki,项目名称:ZentrelaCore,代码行数:58,代码来源:MuteCommand.java

示例7: executeBan

import java.time.ZonedDateTime; //导入方法依赖的package包/类
public boolean executeBan(String name, String uuid, String[] args, String banner, Player banned) {
    String time = args[1].toLowerCase();
    ZonedDateTime endTime = ZonedDateTime.now();
    String lengthDisplay = "";
    if (args[1].startsWith("perm")) {
        endTime = endTime.plusYears(1000);
        lengthDisplay = ChatColor.YELLOW + "permanently" + ChatColor.RED + " banned";
    } else {
        int amount = Integer.parseInt(time.replaceAll("[^0-9]", ""));
        if (time.endsWith("m")) {
            endTime = endTime.plusMinutes(amount);
            lengthDisplay = "banned for " + ChatColor.YELLOW + amount + " minute" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("h")) {
            endTime = endTime.plusHours(amount);
            lengthDisplay = "banned for " + ChatColor.YELLOW + amount + " hour" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("d")) {
            endTime = endTime.plusDays(amount);
            lengthDisplay = "banned for " + ChatColor.YELLOW + amount + " day" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("w")) {
            endTime = endTime.plusWeeks(amount);
            lengthDisplay = "banned for " + ChatColor.YELLOW + amount + " week" + (amount != 1 ? "s" : "");
        } else {
            return false;
        }
    }
    lengthDisplay += ChatColor.RESET;
    StringBuilder sb = new StringBuilder();
    for (int k = 2; k < args.length; k++) {
        sb.append(args[k]);
        sb.append(' ');
    }
    final ZonedDateTime fEndTime = endTime;
    String reason = sb.toString().trim();
    RScheduler.scheduleAsync(plugin, () -> {
        AutoCloseable[] ac_dub2 = SQLManager.prepare("INSERT INTO punishments (name, uuid, ip, type, endTime, reason, giver, startTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ");
        PreparedStatement insert_ban = (PreparedStatement) ac_dub2[0];
        try {
            insert_ban.setString(1, name);
            insert_ban.setString(2, uuid);
            insert_ban.setString(3, PunishmentManager.ips_byUUID.containsKey(uuid) ? PunishmentManager.ips_byUUID.get(uuid) : "");
            insert_ban.setString(4, PunishmentType.BAN.toString());
            insert_ban.setString(5, fEndTime.toString());
            insert_ban.setString(6, reason);
            insert_ban.setString(7, banner);
            insert_ban.setString(8, ZonedDateTime.now().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        SQLManager.execute(ac_dub2);
        SQLManager.close(ac_dub2);
        System.out.println("Executed ban for " + name + ".");
    });
    String announce = ChatColor.YELLOW + name + ChatColor.RED + " was " + lengthDisplay + ChatColor.RED + " by " + ChatColor.YELLOW + banner + ChatColor.RED + " for: " + ChatColor.WHITE + ChatColor.BOLD + reason + ChatColor.RED + ".";
    RMessages.announce(ChatColor.GRAY + "> " + announce);
    if (banned != null && banned.isOnline())
        banned.kickPlayer("You were " + lengthDisplay + " by " + banner + " for: " + reason + ".");
    return true;
}
 
开发者ID:edasaki,项目名称:ZentrelaCore,代码行数:59,代码来源:BanCommand.java


注:本文中的java.time.ZonedDateTime.plusMinutes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。