/*[deutsch]
<p>Erzeugt eine getaktete Uhr, die die aktuelle Uhrzeit nur in der
angegebenen Zeiteinheit anzeigt. </p>

@param   pulse       new pulse
@return  adjusted clock with given pulse
@since   2.1
420130
public AdjustableClock withPulse(TimeUnit pulse) {

        if (pulse == null) {
            throw new NullPointerException("Missing pulse.");
        } else if (pulse == this.pulse) {
            return this;
        }

        return new AdjustableClock(
            this.source,
            pulse,
            this.offsetAmount,
            this.offsetUnit);

    }
155295
public MDecimal getHz() {
		MDecimal result = new MDecimal(currentUnit.getConverterTo(HERTZ)
				.convert(doubleValue()));
		logger.trace(MMarker.GETTER, "Converting from {} to Hertz : {}",
				currentUnit, result);
		return result;
	}
1016422
public static Timer newTimer(String name, TimeUnit unit, TaggingContext context) {
    final MonitorConfig config = MonitorConfig.builder(name).build();
    return new ContextualTimer(config, context, new TimerFactory(unit));
  }
1280162
public Occurred compareTo(Clock c) {
        if(this == c) return Occurred.EQUICONCURRENTLY;
        if(ZERO == c) return Occurred.AFTER;
        if(this == ZERO) return Occurred.BEFORE;
        
        int neg = 0, pos = 0, eq = 0;
        try {
            final long[] dst = c.values();
            final int len = dst.length;
            if(_values.length == len) {
                for(int i = 0; i < len; i++) {
                    long cmp = _values[i] - dst[i];
                    if(cmp < 0) {
                        neg++;
                    } else if(cmp > 0) {
                        pos++;
                    } else {
                        eq++;
                    }
                }
                
                if(eq == len) {
                    return Occurred.EQUICONCURRENTLY;
                } else if(neg == len) {
                    return Occurred.BEFORE;
                } else if(pos == len) {
                    return Occurred.AFTER;
                } else {
                    neg += eq;
                    if(neg == len) {
                        return Occurred.BEFORE;
                    }
                    
                    pos += eq;
                    if(pos == len) {
                        return Occurred.AFTER;
                    }
                    
                    return Occurred.CONCURRENTLY;
                }
            }
        } catch(Exception e) {}
        
        throw new IncomparableClocksException(this, c);
    }
205096
public Date adjustDate(final Date startDate, final int increment, final NonWorkingDayChecker<Date> checker) {
        final Calendar cal = Utils.getCal(startDate);

        while (checker.isNonWorkingDay(cal.getTime())) {
            if (increment < 0) {
                cal.add(Calendar.DAY_OF_MONTH, -1);
            } else {
                cal.add(Calendar.DAY_OF_MONTH, 1);
            }
        }

        return cal.getTime();
    }
869574
public static DateTime getCurrentTime(String timezone) {
    String tz = StringUtils.defaultString(timezone, ConfigurationKeys.DEFAULT_SOURCE_TIMEZONE);
    DateTimeZone dateTimeZone = getTimeZone(tz);
    DateTime currentTime = new DateTime(dateTimeZone);
    return currentTime;
  }
719889
public static <W extends Window> ContinuousEventTimeTrigger<W> of(Time interval) {
		return new ContinuousEventTimeTrigger<>(interval.toMilliseconds());
	}
683978
@VisibleForTesting
    public ClockAndCount getClockAndCountOf(ByteBuffer context, CounterId id)
    {
        int position = findPositionOf(context, id);
        if (position == -1)
            return ClockAndCount.BLANK;

        long clock = context.getLong(position + CounterId.LENGTH);
        long count = context.getLong(position + CounterId.LENGTH + CLOCK_LENGTH);
        return ClockAndCount.create(clock, count);
    }
333986
public static Cell newTimestamp(long rawTimestampValue)
    {
        final Cell cell = new Cell();
        cell.initTimestamp(rawTimestampValue);
        return cell;
    }
582986
public long adjustOffset(long instant, boolean earlierOrLater) {
        // a bit messy, but will work in all non-pathological cases
        
        // evaluate 3 hours before and after to work out if anything is happening
        long instantBefore = instant - 3 * DateTimeConstants.MILLIS_PER_HOUR;
        long instantAfter = instant + 3 * DateTimeConstants.MILLIS_PER_HOUR;
        long offsetBefore = getOffset(instantBefore);
        long offsetAfter = getOffset(instantAfter);
        if (offsetBefore <= offsetAfter) {
            return instant;  // not an overlap (less than is a gap, equal is normal case)
        }
        
        // work out range of instants that have duplicate local times
        long diff = offsetBefore - offsetAfter;
        long transition = nextTransition(instantBefore);
        long overlapStart = transition - diff;
        long overlapEnd = transition + diff;
        if (instant < overlapStart || instant >= overlapEnd) {
          return instant;  // not an overlap
        }
        
        // calculate result
        long afterStart = instant - overlapStart;
        if (afterStart >= diff) {
          // currently in later offset
          return earlierOrLater ? instant : instant - diff;
        } else {
          // currently in earlier offset
          return earlierOrLater ? instant + diff : instant;
        }
    }
1163349
@Override
    ChronoInterval<PlainTimestamp> newInterval(
        Boundary<PlainTimestamp> start,
        Boundary<PlainTimestamp> end
    ) {

        return TimestampIntervalFactory.INSTANCE.between(start, end);

    }
774115
@Pure
	public static double toMetersPerSecond(double value, SpeedUnit inputUnit) {
		switch (inputUnit) {
		case KILOMETERS_PER_HOUR:
			return 3.6 * value;
		case MILLIMETERS_PER_SECOND:
			return value / 1000.;
		case METERS_PER_SECOND:
		default:
		}
		return value;
	}
558431
static public Timestamp adjustTimestamp(Timestamp timestamp)
  {
    long milliToAdjust = ResultUtil.msDiffJulianToGregorian(timestamp);

    if (milliToAdjust != 0)
    {

      if (logger.isDebugEnabled())
      {
        logger.debug("adjust timestamp by {} days", milliToAdjust / 86400000);
      }

      Timestamp newTimestamp = new Timestamp(timestamp.getTime()
                                             + milliToAdjust);

      newTimestamp.setNanos(timestamp.getNanos());

      return newTimestamp;
    }
    else
    {
      return timestamp;
    }
  }
525620
public static ChronoUnit chronoUnit(TimeUnit unit) {
        Objects.requireNonNull(unit, "unit");
        switch (unit) {
            case NANOSECONDS:
                return ChronoUnit.NANOS;
            case MICROSECONDS:
                return ChronoUnit.MICROS;
            case MILLISECONDS:
                return ChronoUnit.MILLIS;
            case SECONDS:
                return ChronoUnit.SECONDS;
            case MINUTES:
                return ChronoUnit.MINUTES;
            case HOURS:
                return ChronoUnit.HOURS;
            case DAYS:
                return ChronoUnit.DAYS;
            default:
                throw new IllegalArgumentException("Unknown TimeUnit constant");
        }
    }
176538
public ChronoFormatter<T> with(StartOfDay startOfDay) {

        if (startOfDay == null) {
            throw new NullPointerException("Missing start of day.");
        }

        return new ChronoFormatter<>(this, this.globalAttributes.withInternal(Attributes.START_OF_DAY, startOfDay));

    }
1013961
public static Clock parseClock(byte[] raw) {
        if(raw == null || raw.length < 8) {
            return Clock.ZERO;
        }
        
        int cnt = raw.length >> 3;
        long[] values = new long[cnt];
        ByteBuffer bb = ByteBuffer.wrap(raw);
        for(int i = 0; i < values.length; i++) {
            values[i] = bb.getLong();
        }
        return new Clock(values);
    }
191435
public Calendar adjustDate(final Calendar startDate, final int increment, final NonWorkingDayChecker<Calendar> checker) {
        final Calendar cal = (Calendar) startDate.clone();

        while (checker.isNonWorkingDay(cal)) {
            cal.add(Calendar.DAY_OF_MONTH, increment);
        }

        return cal;
    }