customizable date display format
This commit is contained in:
parent
09eee68e51
commit
571041f8f8
|
@ -13,6 +13,14 @@
|
||||||
# leaving blank will disable this
|
# leaving blank will disable this
|
||||||
append_path = ""
|
append_path = ""
|
||||||
|
|
||||||
|
[formatting]
|
||||||
|
# whether to format dates as relative or absolute
|
||||||
|
# "relative" = relative, "absolute" = absolute
|
||||||
|
# do note that absolute times can result in uglier
|
||||||
|
# times due to colons being forbiddne in certain
|
||||||
|
# spots
|
||||||
|
date = "relative"
|
||||||
|
|
||||||
[accounts]
|
[accounts]
|
||||||
# allow new accounts to be created
|
# allow new accounts to be created
|
||||||
allow_registration = true
|
allow_registration = true
|
||||||
|
@ -30,4 +38,12 @@ allow_demon_votes = true
|
||||||
# will go from NA to the average
|
# will go from NA to the average
|
||||||
min_votes = 10
|
min_votes = 10
|
||||||
# same as above, but for demon ratings
|
# same as above, but for demon ratings
|
||||||
min_demon_votes = 10
|
min_demon_votes = 10
|
||||||
|
|
||||||
|
[levels]
|
||||||
|
# prevent users from deleting their own levels
|
||||||
|
# if they are rated
|
||||||
|
prevent_deletion_rated = true
|
||||||
|
# prevent users from deleting their own levels
|
||||||
|
# if they are featured
|
||||||
|
prevent_deletion_featured = true
|
|
@ -98,7 +98,7 @@ CrystalGauntlet.endpoints["/getGJLevelScores211.php"] = ->(body : String): Strin
|
||||||
3 => percent,
|
3 => percent,
|
||||||
6 => i,
|
6 => i,
|
||||||
13 => coins,
|
13 => coins,
|
||||||
42 => Format.fmt_timespan(Time.utc - Time.parse(set_at, Format::TIME_FORMAT, Time::Location::UTC))
|
42 => Time.parse(set_at, Format::TIME_FORMAT, Time::Location::UTC)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ CrystalGauntlet.endpoints["/getGJAccountComments20.php"] = ->(body : String): St
|
||||||
4 => likes,
|
4 => likes,
|
||||||
5 => 0,
|
5 => 0,
|
||||||
7 => likes < -3, # todo: config?
|
7 => likes < -3, # todo: config?
|
||||||
#9 => Format.fmt_timespan(Time.utc - Time.parse(created_at, Format::TIME_FORMAT, Time::Location::UTC)),
|
9 => Time.parse(created_at, Format::TIME_FORMAT, Time::Location::UTC),
|
||||||
6 => id
|
6 => id
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,10 @@ module CrystalGauntlet::Format
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
|
TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
|
||||||
|
# used when sending back to the client as an absolute date
|
||||||
|
TIME_FORMAT_GD_FRIENDLY = "%d/%m/%Y %H.%M"
|
||||||
|
# safe to send back in comments
|
||||||
|
TIME_FORMAT_USER_FRIENDLY = "%d/%m/%Y %H:%M"
|
||||||
|
|
||||||
def fmt_timespan(s : Time::Span) : String
|
def fmt_timespan(s : Time::Span) : String
|
||||||
seconds = s.total_seconds.floor()
|
seconds = s.total_seconds.floor()
|
||||||
|
@ -26,14 +30,24 @@ module CrystalGauntlet::Format
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fmt_value(v) : String
|
def fmt_time(s : Time, colon_safe=false) : String
|
||||||
|
s.to_s(colon_safe ? TIME_FORMAT_USER_FRIENDLY : TIME_FORMAT_GD_FRIENDLY)
|
||||||
|
end
|
||||||
|
|
||||||
|
def fmt_value(v, colon_safe=false) : String
|
||||||
case v
|
case v
|
||||||
when Bool
|
when Bool
|
||||||
v ? "1" : "0"
|
v ? "1" : "0"
|
||||||
when String
|
when String
|
||||||
v
|
v
|
||||||
when Time::Span
|
when Time::Span
|
||||||
fmt_span(v)
|
fmt_timespan(v)
|
||||||
|
when Time
|
||||||
|
if config_get("formatting.date") == "relative"
|
||||||
|
fmt_timespan(Time.utc - v)
|
||||||
|
else
|
||||||
|
fmt_time(v, colon_safe)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
v.to_s
|
v.to_s
|
||||||
end
|
end
|
||||||
|
@ -44,11 +58,11 @@ module CrystalGauntlet::Format
|
||||||
end
|
end
|
||||||
|
|
||||||
def fmt_song(hash) : String
|
def fmt_song(hash) : String
|
||||||
hash.map_with_index{ |(i, v)| "#{i}~|~#{fmt_value(v)}" }.join("~|~")
|
hash.map_with_index{ |(i, v)| "#{i}~|~#{fmt_value(v, true)}" }.join("~|~")
|
||||||
end
|
end
|
||||||
|
|
||||||
def fmt_comment(hash) : String
|
def fmt_comment(hash) : String
|
||||||
hash.map_with_index{ |(i, v)| "#{i}~#{fmt_value(v)}" }.join("~")
|
hash.map_with_index{ |(i, v)| "#{i}~#{fmt_value(v, true)}" }.join("~")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue