All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.dv8tion.jda.api.utils.TimeFormat Maven / Gradle / Ivy

Go to download

Java wrapper for the popular chat & VOIP service: Discord https://discord.com

There is a newer version: 5.1.0
Show newest version
/*
 * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.dv8tion.jda.api.utils;

import net.dv8tion.jda.internal.utils.Checks;

import javax.annotation.Nonnull;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.TemporalAccessor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Utility enum used to provide different markdown styles for timestamps.
 * 
These can be used to represent a unix epoch timestamp in different formats. * *

These timestamps are rendered by the individual receiving discord client in a local timezone and language format. * Each timestamp can be displayed with different {@link TimeFormat TimeFormats}. * *

Example
*

{@code
 * channel.sendMessage("Current Time: " + TimeFormat.RELATIVE.now()).queue();
 * channel.sendMessage("Uptime: " + TimeFormat.RELATIVE.format(getStartTime())).queue();
 * }
*/ public enum TimeFormat { /** Formats time as {@code 18:49} or {@code 6:49 PM} */ TIME_SHORT("t"), /** Formats time as {@code 18:49:26} or {@code 6:49:26 PM} */ TIME_LONG("T"), /** Formats date as {@code 16/06/2021} or {@code 06/16/2021} */ DATE_SHORT("d"), /** Formats date as {@code 16 June 2021} */ DATE_LONG("D"), /** Formats date and time as {@code 16 June 2021 18:49} or {@code June 16, 2021 6:49 PM} */ DATE_TIME_SHORT("f"), /** Formats date and time as {@code Wednesday, 16 June 2021 18:49} or {@code Wednesday, June 16, 2021 6:49 PM} */ DATE_TIME_LONG("F"), /** Formats date and time as relative {@code 18 minutes ago} or {@code 2 days ago} */ RELATIVE("R"), ; /** * The default time format used when no style is provided. */ public static final TimeFormat DEFAULT = DATE_TIME_SHORT; /** * {@link Pattern} used for {@link #parse(String)}. * *

Groups
*

* * * * * * * * * * * * * * * * * * * * * *
Javadoc is stupid, this is not a required tag
IndexNameDescription
0N/AThe entire timestamp markdown
1timeThe timestamp value as a unix epoch in second precision
2styleThe style used for displaying the timestamp (single letter flag)
* * @see #parse(String) */ public static final Pattern MARKDOWN = Pattern.compile("-?\\d{1,17})(?::(?