Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using custom time format #798

Merged
merged 2 commits into from
Feb 4, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,11 @@ please consider changing to GITEA_CUSTOM`)
"StampMicro": time.StampMicro,
"StampNano": time.StampNano,
}[Cfg.Section("time").Key("FORMAT").MustString("RFC1123")]
// Determine When using custom time format like '2006-01-02 15:04:05'
if (TimeFormat == "") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MustString("RFC1123") means default is RFC1123, so TimeFormat will never be empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No .. this is not assignment to TimeFormat e.g. `TimeFormat = Cfg.Section("time").Key("FORMAT").MustString("RFC1123")

Copy link
Contributor Author

@Ahed91 Ahed91 Jan 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the key Cfg.Section("time").Key("FORMAT").MustString("RFC1123") was not present in the map. TimeFormat will be ""

Copy link
Member

@lunny lunny Jan 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cfg.Section("time").Key("FORMAT").MustString("RFC1123") will always return a string, will never be empty. And RFC1123 is in the map, so TimeFormat will never be empty.

Copy link
Contributor Author

@Ahed91 Ahed91 Jan 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok forget my comments for now --> that's the problem which prevents me from using custom time format ..
in my conf/app.ini

[time]
FORMAT = 2006-01-02 15:04:05

this FORMAT is not in the map ... so TIMEFORMAT will be empty ..
this code will save 2006-01-02 15:04:05 in TIMEFORMAT
so when using function like TimeSince will return

<span class="time-since poping up" title="" data-content="2017-01-30 11:56:19" data-variation="inverted tiny">5 ساعات مضت</span>

instead of

<span class="time-since poping up" title="" data-content="" data-variation="inverted tiny">5 ساعات مضت</span>

TimeFormat = Cfg.Section("time").Key("FORMAT").String()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs validation.

log.Trace("Custom TimeFormat: %s", TimeFormat)
}

RunUser = Cfg.Section("").Key("RUN_USER").MustString(user.CurrentUsername())
// Does not check run user when the install lock is off.
Expand Down