📚
YAGPDB
  • YAGPDB Coding System - Documentation
  • Getting Started
  • Useful Functions
  • Primary Level
    • The Dot and Variables
      • User
      • Guild / Server
      • Member
      • Channel
      • Message
      • Reaction
      • Time
    • Custom Types
    • Functions
      • Type Conversion
      • String Manipulation
      • Math Functions
      • Message Functions
      • Mentions
      • Role Functions
      • Current User
      • Miscellaneous
      • ExecCC
    • Conditional Branching
  • Intermediate Level
  • Database
  • Range Action
  • With Action
  • Custom Embeds
  • Advanced Level
    • Using RegEx
  • Custom Commands Examples
    • Texas Hold'em
Powered by GitBook
On this page
  • Field
  • Function
  • More Info

Was this helpful?

  1. Primary Level
  2. The Dot and Variables

Time

Time goes on, and you are becoming a pro

PreviousReactionNextCustom Types

Last updated 5 years ago

Was this helpful?

Time in general uses Golang's time package library > and also this although slightly different syntax all applies here > .

Field

Field

Description

.DiscordEpoch

Gives you Discord Epoch time in time.Time. {{.DiscordEpoch.Unix}} would return in seconds > 1420070400.

.UnixEpoch

Gives you Unix Epoch time in time.Time.

.TimeHour

Variable of time.Duration type and returns 1 hour > 1h0m0s.

.TimeMinute

Variable of time.Duration type and returns 1 minute > 1m0s.

.TimeSecond

Variable of time.Duration type and returns 1 second > 1s.

Function

Function

Description

currentTime

Gets the current time, value is of type time.Time which can be used in a custom embed.

formatTime Time "arg"

Outputs given time in RFC822 formatting, first argument Time shows it needs to be of type time.Time, also with extra layout if second argument is given - e.g. {{formatTime currentUserCreated "3:04PM"}} would output 11:22AM if that would have been user's creating time.

humanizeDurationHours

humanizeDurationMinutes

Sames as humanizeDurationHours, this time duration is returned in minutes - e.g. {{humanizeDurationMinutes 3500000000000}} would return 58 minutes.

humanizeDurationSeconds

Sames as both humanize functions above, this time duration is returned in seconds - e.g. {{humanizeDurationSeconds 3500000000000}} would return 58 minutes and 20 seconds.

humanizeTimeSinceDays

Returns time passed since given argument of type time.Time in human readable format - e.g. {{humanizeTimeSinceDays currentUserCreated}}

newDate year month day hour minute second [timezone]

Example:

  • To demonstrate humanizeDurationHours and also how to parse a timestamp, output will be like whois command shows user's join server age. {{humanizeDurationHours (currentTime.Sub .Member.JoinedAt.Parse)}}

  • To demonstrate newDate to get Epoch times. {{$unixEpoch := newDate 1970 1 1 0 0 0}} in seconds > {{$unixEpoch.Unix}} {{$discordEpoch := newDate 2015 1 1 0 0 0}} in seconds > {{$discordEpoch.Unix}}

More Info

The currentTime template is very extensive and can be used for displaying the current time, for different time zones, or in embeds in the "timestamp" field.

As timestamp in an embed
{{ $embed := cembed "timestamp" currentTime }}
{{/* golang time formating is POSIX form 0 1 2 3 4 5 6 > Mon 2 Jan 15:04:05 2006 (timezone calculation is omitted) */}}
{{/* currentTime.UTC.Format "15:04"  > gives current time in UTC */}}
{{/* ".Add" adds time in nanoseconds, in this example 2 hours have been added for UTC+2 */}}
{{ $marker := "void" }}

{{ if gt ( toInt ( currentTime.UTC.Format "15" ) ) 12 }}
{{ $marker = "PM" }}
{{ else }}
{{ $marker = "AM" }}
{{ end }}

{{/* current time in UTC+2 and in 12H format */}}
{{ ( joinStr " " ( ( currentTime.Add 7200000000000 ).Format "3:04"  ) $marker ) }}

It's the {{currentTime.Day}}. of {{currentTime.Month}} in the year {{currentTime.Year}}!
{{/*Protip: you can put PM in the format string as "3:04PM"
the variable $marker is there just to show if comparison as well.
More > https://golang.org/pkg/time/#pkg-constants*/}}

Returns given integer (whole number) or time.Duration argument in nanoseconds in human readable format - as how long it would take to get towards given time - e.g. {{humanizeDurationHours 9000000000000000000}} returns 285 years 20 weeks 6 days and 16 hours. More in .

Returns new type time.Time object in UTC using given syntax (all arguments need to be of type int), for example > {{humanizeDurationHours ((newDate 2059 1 2 12 34 56).Sub currentTime)}} will give you how much time till year 2059 January 2nd 12:34:56. More examples in .

timezone is an optional string argument which uses golang's function and For example: {{newDate 2020 4 20 12 34 56 "Atlantic/Reykjavik"}} would return that time in GMT+0.

even more in depth here >

https://golang.org/pkg/time/#time
https://gobyexample.com/time
https://golang.org/pkg/time/
LoadLocation
ZONEINFO syntax.
Example
Example