Tabnine Logo
DateUtils$Duration
Code IndexAdd Tabnine to your IDE (free)

How to use
DateUtils$Duration
in
com.atlassian.core.util

Best Java code snippets using com.atlassian.core.util.DateUtils$Duration (Showing top 20 results out of 315)

origin: com.atlassian.core/atlassian-core-utils

if (numSecs >= Duration.HOUR.getSeconds())
  long hours = numSecs / Duration.HOUR.getSeconds();
  result.append(hours).append(' ');
  numSecs = numSecs % Duration.HOUR.getSeconds();
if (numSecs >= Duration.MINUTE.getSeconds())
  long minute = numSecs / Duration.MINUTE.getSeconds();
  result.append(minute).append(' ');
    numSecs = numSecs % Duration.MINUTE.getSeconds();
if (numSecs >= 1 && numSecs < Duration.MINUTE.getSeconds())
origin: com.atlassian.core/atlassian-core-utils

months = difference / Duration.MONTH.getMilliseconds();
if (months > 0)
  difference = difference % Duration.MONTH.getMilliseconds();
  if (months > 1)
  days = difference / Duration.DAY.getMilliseconds();
  if (days > 0)
    difference = difference % Duration.DAY.getMilliseconds();
    if (days > 1)
  hours = difference / Duration.HOUR.getMilliseconds();
  if (hours > 0)
    difference = difference % Duration.HOUR.getMilliseconds();
    if (hours > 1)
  minutes = difference / Duration.MINUTE.getMilliseconds();
  if (minutes > 0)
    difference = difference % Duration.MINUTE.getMilliseconds();
    if (minutes > 1)
  seconds = difference / Duration.SECOND.getMilliseconds();
  if (seconds > 0)
origin: com.atlassian.core/atlassian-core

private static String validateDurationUnit(final String durationString, final Duration duration)
    throws InvalidDurationException {
  if (durationString.length() > 1) {
    String singular = duration.name().toLowerCase();
    String plural = duration.name().toLowerCase() + "s";
    if (durationString.contains(plural)) {
      return durationString.substring(durationString.indexOf(plural));
    } else if (durationString.contains(singular)) {
      return durationString.substring(durationString.indexOf(singular));
    } else {
      throw new InvalidDurationException("Not a valid durationString string");
    }
  }
  return durationString.substring(1);
}
origin: com.atlassian.core/atlassian-core

months = difference / Duration.MONTH.getMilliseconds();
if (months > 0) {
  difference = difference % Duration.MONTH.getMilliseconds();
  if (months > 1) {
    sb.append(months).append(" ").append(getText(resourceBundle, "core.dateutils.months")).append(", ");
  days = difference / Duration.DAY.getMilliseconds();
  if (days > 0) {
    difference = difference % Duration.DAY.getMilliseconds();
    if (days > 1) {
      sb.append(days).append(" ").append(getText(resourceBundle, "core.dateutils.days")).append(", ");
  hours = difference / Duration.HOUR.getMilliseconds();
  if (hours > 0) {
    difference = difference % Duration.HOUR.getMilliseconds();
    if (hours > 1) {
      sb.append(hours).append(" ").append(getText(resourceBundle, "core.dateutils.hours")).append(", ");
  minutes = difference / Duration.MINUTE.getMilliseconds();
  if (minutes > 0) {
    difference = difference % Duration.MINUTE.getMilliseconds();
    if (minutes > 1) {
      sb.append(minutes).append(" ").append(getText(resourceBundle, "core.dateutils.minutes")).append(", ");
  seconds = difference / Duration.SECOND.getMilliseconds();
  if (seconds > 0) {
    if (seconds > 1) {
origin: com.atlassian.core/atlassian-core

if (numSecs >= Duration.HOUR.getSeconds()) {
  long hours = numSecs / Duration.HOUR.getSeconds();
  result.append(hours).append(' ');
  numSecs = numSecs % Duration.HOUR.getSeconds();
if (numSecs >= Duration.MINUTE.getSeconds()) {
  long minute = numSecs / Duration.MINUTE.getSeconds();
  result.append(minute).append(' ');
    numSecs = numSecs % Duration.MINUTE.getSeconds();
if (numSecs >= 1 && numSecs < Duration.MINUTE.getSeconds()) {
  result.append(numSecs).append(' ');
origin: com.atlassian.core/atlassian-core-utils

time = Long.parseLong(durationStr.trim()) * defaultUnit.getSeconds();
        time *= Duration.MINUTE.getSeconds();
        break;
      case(int) 'h':
        remainingDurationStr = validateDurationUnit(durationStr.substring(i), "hours");
        time *= Duration.HOUR.getSeconds();
        break;
      case(int) 'd':
origin: com.atlassian.core/atlassian-core

try // detect if we just have a number
  time = Long.parseLong(durationStr.trim()) * defaultUnit.getModifiedSeconds(secondsPerDay, secondsPerWeek);
} catch (Exception ex) // otherwise get the value
origin: com.atlassian.core/atlassian-core

long s = (long) (unit.getModifiedSeconds(secondsPerDay, secondsPerWeek) * n.doubleValue());
origin: com.atlassian.core/atlassian-core

if (l >= Duration.HOUR.getSeconds()) {
  result.append((l / Duration.HOUR.getSeconds()));
  result.append("h ");
  l = l % Duration.HOUR.getSeconds();
if (l >= Duration.MINUTE.getSeconds()) {
  result.append((l / Duration.MINUTE.getSeconds()));
  result.append("m ");
origin: com.atlassian.core/atlassian-core

case (int) 'm':
  validateDurationUnit(unit.substring(0), Duration.MINUTE);
  time = Duration.MINUTE.getSeconds();
  break;
case (int) 'h':
  validateDurationUnit(unit.substring(0), Duration.HOUR);
  time = Duration.HOUR.getSeconds();
  break;
case (int) 'd':
origin: com.atlassian.jira/jira-api

final TimeFormatWithPrecision result = calculateFractionalTimeUnit(duration, hoursPerDay.multiply(BigDecimal.valueOf(DateUtils.Duration.HOUR.getSeconds())).intValueExact(), i18nBean, UNIT_DAY, scale, userLocale);
if (result.remainder == 0)
origin: com.atlassian.core/atlassian-core-utils

if (l >= Duration.HOUR.getSeconds())
  result.append((l / Duration.HOUR.getSeconds()));
  result.append("h ");
  l = l % Duration.HOUR.getSeconds();
if (l >= Duration.MINUTE.getSeconds())
  result.append((l / Duration.MINUTE.getSeconds()));
  result.append("m ");
origin: com.atlassian.jira/jira-api

final TimeFormatWithPrecision result = calculateFractionalTimeUnit(duration, (int) DateUtils.Duration.HOUR.getSeconds(), i18nBean, UNIT_HOUR, scale, userLocale);
if (result.remainder == 0)
    return calculateFractionalTimeUnit(result.remainder, (int) DateUtils.Duration.MINUTE.getSeconds(), i18nBean, UNIT_MINUTE, scale, userLocale).formatted;
    return result.formatted + ' ' + calculateFractionalTimeUnit(result.remainder, (int) DateUtils.Duration.MINUTE.getSeconds(), i18nBean, UNIT_MINUTE, scale, userLocale).formatted;
origin: com.atlassian.jira/jira-core

public String doDefault() throws Exception
{
  // Retrieve the worklog
  worklog = worklogService.getById(getJiraServiceContext(), getWorklogId());
  if (worklog == null)
  {
    addErrorMessage(getText("logwork.error.update.invalid.id", (getWorklogId() == null) ? null : getWorklogId().toString()));
    return ERROR;
  }
  if (!worklogService.hasPermissionToUpdate(getJiraServiceContext(), worklog))
  {
    //user doesn't have permission to run this action
    return "securitybreach";
  }
  //pre-populate the fields
  final BigDecimal hoursPerDay = getHoursPerDay();
  final BigDecimal daysPerWeek = getDaysPerWeek();
  final BigDecimal secondsPerHour = BigDecimal.valueOf(DateUtils.Duration.HOUR.getSeconds());
  final long secondsPerDay = hoursPerDay.multiply(secondsPerHour).longValueExact();
  final long secondsPerWeek = daysPerWeek.multiply(hoursPerDay).multiply(secondsPerHour).longValueExact();
  setTimeLogged(DateUtils.getDurationStringSeconds(worklog.getTimeSpent(), secondsPerDay, secondsPerWeek));
  setStartDate(getFormattedStartDate(worklog.getStartDate()));
  setComment(worklog.getComment());
  setCommentLevel(CommentVisibility.getCommentLevelFromLevels(worklog.getGroupLevel(), worklog.getRoleLevelId()));
  return super.doDefault();
}
origin: com.atlassian.jira/jira-core

public TimeTrackingAdmin(final ApplicationProperties applicationProperties, final FieldManager fieldManager, final JiraDurationUtils jiraDurationUtils, final JiraAuthenticationContext authenticationContext, final PluginAccessor pluginAccessor, final ReindexMessageManager reindexMessageManager, final FeatureManager featureManager)
{
  this.applicationProperties = applicationProperties;
  this.fieldManager = fieldManager;
  this.jiraDurationUtils = jiraDurationUtils;
  this.authenticationContext = authenticationContext;
  this.pluginAccessor = pluginAccessor;
  this.reindexMessageManager = notNull("reindexMessageManager", reindexMessageManager);
  this.featureManager = featureManager;
  hoursPerDay = applicationProperties.getDefaultBackedString(APKeys.JIRA_TIMETRACKING_HOURS_PER_DAY);
  daysPerWeek = applicationProperties.getDefaultBackedString(APKeys.JIRA_TIMETRACKING_DAYS_PER_WEEK);
  timeTrackingFormat = applicationProperties.getDefaultBackedString(APKeys.JIRA_TIMETRACKING_FORMAT);
  try
  {
    defaultUnit = DateUtils.Duration.valueOf(applicationProperties.getDefaultBackedString(APKeys.JIRA_TIMETRACKING_DEFAULT_UNIT));
  }
  catch (IllegalArgumentException e)
  {
    defaultUnit = DateUtils.Duration.MINUTE;
  }
  catch (NullPointerException e)
  {
    defaultUnit = DateUtils.Duration.MINUTE;
  }
}
origin: com.atlassian.core/atlassian-core-utils

/**
 * Given a duration string, get the number of seconds it represents (all case insensitive):
 * <ul>
 * <li>w = weeks
 * <li>d = days
 * <li>h = hours
 * <li>m = minutes
 * </ul>
 * ie 2h = 7200, 60m = 3600, 3d = 259200, 30m
 *
 * @param durationStr the duration string
 * @param defaultUnit the unit used when another is not specified in the durationStr
 * @return the duration in seconds
 * @throws InvalidDurationException if the duration is invalid
 */
public static long getDuration(final String durationStr, final Duration defaultUnit) throws InvalidDurationException
{
  return getDurationSeconds(durationStr, Duration.DAY.getSeconds(), Duration.WEEK.getSeconds(), defaultUnit);
}
origin: com.atlassian.jira/jira-api

/**
 * Turn a duration string into the number of seconds that it represents, taking into account JIRA's configuration
 * (i.e. how many hours are in a day, how many days are in a week, etc)
 *
 * @param duration string in JIRA's duration format (i.e. "20h")
 * @param locale Locale to use when interpreting the duration string
 * @return number of seconds in the duration string
 * @throws InvalidDurationException when the duration cannot be parsed
 */
public Long parseDuration(final String duration, Locale locale) throws InvalidDurationException
{
  //Retrieve the number of hours per day and number of days per week
  final BigDecimal hoursPerDay = timeTrackingConfiguration.getHoursPerDay();
  final BigDecimal daysPerWeek = timeTrackingConfiguration.getDaysPerWeek();
  final BigDecimal secondsPerHour = BigDecimal.valueOf(DateUtils.Duration.HOUR.getSeconds());
  final long secondsPerDay = hoursPerDay.multiply(secondsPerHour).longValueExact();
  final long secondsPerWeek = daysPerWeek.multiply(hoursPerDay).multiply(secondsPerHour).longValueExact();
  return DurationUtils.getDurationSeconds(duration, secondsPerDay, secondsPerWeek, timeTrackingConfiguration.getDefaultUnit(), locale, TOKEN_MAP);
}
origin: com.atlassian.jira/jira-core

public String getDefaultTimeUnit()
{
  final Map<String, String> map = MapBuilder.<String, String>newBuilder()
      .add(DateUtils.Duration.MINUTE.name(), getText("core.dateutils.minute"))
      .add(DateUtils.Duration.HOUR.name(), getText("core.dateutils.hour"))
      .add(DateUtils.Duration.DAY.name(), getText("core.dateutils.day"))
      .add(DateUtils.Duration.WEEK.name(), getText("core.dateutils.week")).toMap();
  DateUtils.Duration defaultUnit;
  try
  {
    defaultUnit = DateUtils.Duration.valueOf(applicationProperties.getDefaultBackedString(APKeys.JIRA_TIMETRACKING_DEFAULT_UNIT));
  }
  catch (IllegalArgumentException e)
  {
    defaultUnit = DateUtils.Duration.MINUTE;
  }
  catch (NullPointerException e)
  {
    defaultUnit = DateUtils.Duration.MINUTE;
  }
  return map.get(defaultUnit.toString());
}
origin: com.atlassian.core/atlassian-core

/**
 * Given a duration string, get the number of seconds it represents (all case insensitive):
 * <ul>
 * <li>w = weeks
 * <li>d = days
 * <li>h = hours
 * <li>m = minutes
 * </ul>
 * ie 2h = 7200, 60m = 3600, 3d = 259200, 30m
 *
 * @param durationStr the duration string
 * @param defaultUnit the unit used when another is not specified in the durationStr
 * @return the duration in seconds
 * @throws InvalidDurationException if the duration is invalid
 */
public static long getDuration(final String durationStr, final Duration defaultUnit) throws InvalidDurationException {
  return getDurationSeconds(durationStr, Duration.DAY.getSeconds(), Duration.WEEK.getSeconds(), defaultUnit);
}
origin: com.atlassian.core/atlassian-core-utils

/**
 * Converts a number of seconds into a pretty formatted data string.  The resolution is in minutes.  So if the number of seconds is greater than a minute, it will
 * only be shown down top minute resolution.  If the number of seconds is less than a minute it will be shown in seconds.
 * <p/>
 * So for example <code>76</code> becomes <code>'1 minute'</code>, while <code>42</code> becomes <code>'42 seconds'</code>
 *
 * @param numSecs        the number of seconds in the duration
 * @param hoursPerDay    the hours in a day
 * @param daysPerWeek    the number of days in a week
 * @param resourceBundle a resouce bundle for i18n
 * @return a string in readable pretty duration format, using minute resolution
 */
public static String getDurationPretty(long numSecs, int hoursPerDay, int daysPerWeek, ResourceBundle resourceBundle)
{
  long secondsInDay = hoursPerDay * Duration.HOUR.getSeconds();
  long secondsPerWeek = daysPerWeek * secondsInDay;
  return getDurationPrettySeconds(numSecs, secondsInDay, secondsPerWeek, resourceBundle, false);
}
com.atlassian.core.utilDateUtils$Duration

Most used methods

  • getSeconds
  • getMilliseconds
  • name
  • valueOf
  • getModifiedSeconds
    Sometimes customers configure the meaning of "day" or "week" to mean something like "1 day = 8 hours
  • toString
  • values

Popular in Java

  • Making http requests using okhttp
  • onCreateOptionsMenu (Activity)
  • putExtra (Intent)
  • scheduleAtFixedRate (Timer)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now