Class: Discordrb::TimestampMarkdown

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/data/timestamp.rb

Overview

A timestamp referenced in a message via markdown.

Constant Summary collapse

STYLES =

Mapping of timestamp styles.

{
  short_time: 't', # 16:20
  long_time: 'T', # 16:20:30
  short_date: 'd', # 20/04/2021
  long_date: 'D', # 20 April 2021
  short_datetime: 'f', # 20 April 2021 16:20
  long_datetime: 'F', # Tuesday, 20 April 2021 16:20
  relative: 'R', # 2 months ago
  simple_datetime: 's', # 20/04/2021, 16:20
  medium_datetime: 'S' # 20/04/2021, 16:20:30
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#timeTime (readonly)

Returns the time that the timestamp is referencing.

Returns:

  • (Time)

    the time that the timestamp is referencing.



20
21
22
# File 'lib/discordrb/data/timestamp.rb', line 20

def time
  @time
end

Instance Method Details

#long_date?true, false

Returns whether or not the timestamp is displayed in a format such as 20 April 2021.

Returns:

  • (true, false)

    whether or not the timestamp is displayed in a format such as 20 April 2021.



63
64
65
66
67
# File 'lib/discordrb/data/timestamp.rb', line 63

STYLES.each do |name, value|
  define_method("#{name}?") do
    style == value
  end
end

#long_datetime?true, false

Returns whether or not the timestamp is displayed in a format such as Tuesday, 20 April 2021 16:20.

Returns:

  • (true, false)

    whether or not the timestamp is displayed in a format such as Tuesday, 20 April 2021 16:20.



63
64
65
66
67
# File 'lib/discordrb/data/timestamp.rb', line 63

STYLES.each do |name, value|
  define_method("#{name}?") do
    style == value
  end
end

#long_time?true, false

Returns whether or not the timestamp is displayed in a format such as 16:20:30.

Returns:

  • (true, false)

    whether or not the timestamp is displayed in a format such as 16:20:30.



63
64
65
66
67
# File 'lib/discordrb/data/timestamp.rb', line 63

STYLES.each do |name, value|
  define_method("#{name}?") do
    style == value
  end
end

#medium_datetime?true, false

Returns whether or not the timestamp is displayed in a format such as 20/04/2021, 16:20:30.

Returns:

  • (true, false)

    whether or not the timestamp is displayed in a format such as 20/04/2021, 16:20:30.



63
64
65
66
67
# File 'lib/discordrb/data/timestamp.rb', line 63

STYLES.each do |name, value|
  define_method("#{name}?") do
    style == value
  end
end

#relative?true, false

Returns whether or not the timestamp is displayed in a format such as 2 months ago.

Returns:

  • (true, false)

    whether or not the timestamp is displayed in a format such as 2 months ago.



63
64
65
66
67
# File 'lib/discordrb/data/timestamp.rb', line 63

STYLES.each do |name, value|
  define_method("#{name}?") do
    style == value
  end
end

#short_date?true, false

Returns whether or not the timestamp is displayed in a format such as 20/04/2021.

Returns:

  • (true, false)

    whether or not the timestamp is displayed in a format such as 20/04/2021.



63
64
65
66
67
# File 'lib/discordrb/data/timestamp.rb', line 63

STYLES.each do |name, value|
  define_method("#{name}?") do
    style == value
  end
end

#short_datetime?true, false

Returns whether or not the timestamp is displayed in a format such as 20 April 2021 16:20.

Returns:

  • (true, false)

    whether or not the timestamp is displayed in a format such as 20 April 2021 16:20.



63
64
65
66
67
# File 'lib/discordrb/data/timestamp.rb', line 63

STYLES.each do |name, value|
  define_method("#{name}?") do
    style == value
  end
end

#short_time?true, false

Returns whether or not the timestamp is displayed in a format such as 16:20.

Returns:

  • (true, false)

    whether or not the timestamp is displayed in a format such as 16:20.



63
64
65
66
67
# File 'lib/discordrb/data/timestamp.rb', line 63

STYLES.each do |name, value|
  define_method("#{name}?") do
    style == value
  end
end

#simple_datetime?true, false

Returns whether or not the timestamp is displayed in a format such as 20/04/2021, 16:20.

Returns:

  • (true, false)

    whether or not the timestamp is displayed in a format such as 20/04/2021, 16:20.



63
64
65
66
67
# File 'lib/discordrb/data/timestamp.rb', line 63

STYLES.each do |name, value|
  define_method("#{name}?") do
    style == value
  end
end

#styleString

Get the specifier used to determine the style of the timestamp.

Returns:

  • (String)

    the formatting specifier used to display the timestamp.



30
31
32
# File 'lib/discordrb/data/timestamp.rb', line 30

def style
  @style || 'f'
end

#to_sString

Get a string that will allow you to display the time in the Discord client.

Returns:

  • (String)

    The timestamp serialized as a string for the Discord client.



36
37
38
# File 'lib/discordrb/data/timestamp.rb', line 36

def to_s
  Discordrb.timestamp(@time, @style)
end