Wikipedia:Comments in Local Time
{{shortcut|WP:LOCO|WP:LOCALIZE|WP:LOCALISE}}
Comments in Local Time (source code) is a gadget that changes UTC-based dates, such as those in signatures, to be relative to the user's local time. It also adds the day of the week to dates, and uses common phrases to describe dates (i.e., Today, 2 months ago, etc.).
This script uses plain JavaScript, making pages load significantly faster than if the script used jQuery.
__TOC__
{{clear}}
Installation
To enable this gadget, navigate to:
- {{myprefs|Gadgets|Browsing|check="{{int:Gadget-CommentsInLocalTime}}"}}
- click {{button|Save}}
- consider bypassing your browser's cache.
Alternatively, this script can also be installed by copying the code below to your custom JavaScript file at Special:MyPage/common.js:
Examples
00:00 1 January 2011 (UTC) is changed to {{nowrap|7:00 pm, 31 December 2010, Friday (1 month, 2 days ago) (UTC-5).}}
The date is shown in your local time, based on your computer's timezone setting. The display is highly customizable through the use of options. For instance:
00:00 1 January 2011 (UTC) can instead be changed to {{nowrap|19:00, December 31, 2010, (33 days ago) (UTC-5).}}
Dates that are either today, yesterday, or tomorrow are shown with relative dates, such as {{nowrap|Today, 1:00 am (UTC-5).}}
Settings
=Default settings=
dateDifference: true,
dateFormat: 'dmy',
dayOfWeek: true,
dropDays: 0,
dropMonths: 0,
timeFirst: true,
twentyFourHours: false,
};
=Custom settings=
To change the default settings, copy the above code to your custom JavaScript file, placing it before the {{bcode|importScript}} used to import this script, and change the values after the colon. The settings are explained in greater detail below. After changing the settings, force your browser to perform a full reload of a talk page to see the effect.
;dateDifference
: Shows the difference in terms of days, months, and years from the timestamp and today's date.
: Options: {{bcode|true}} to show the difference between the timestamp and today's date, and {{bcode|false}} to hide the difference
;dateFormat
: Changes the date's format.
: Options: {{bcode|'dmy'}} for {{nowrap|"1 January 2009"}}, {{bcode|'mdy'}} for {{nowrap|"January 1, 2009"}}, and {{bcode|'ymd'}} for "2009-01-01"
;dayOfWeek
: Displays the day of the week.
: Options: {{bcode|true}} to add the day of the week, and {{bcode|false}} to suppress the day of the week
;dropDays
: Number of days in difference at which point only the number of months is displayed.
: Options: {{bcode|0}} to always show the number of days, and >0 to set a maximum number of days to show
;dropMonths
: Number of months in difference at which point only the number of years is displayed.
: Options: {{bcode|0}} to always show the number of months, and >0 to set a maximum number of months to show
;timeFirst
: Changes the order in which the time and date appears in timestamps.
: Options: {{bcode|true}} for the time to appear before the date, and {{bcode|false}} for the date to appear before the time
;twentyFourHours
: Uses a 24-hour clock instead of the default 12-hour clock.
: Options: {{bcode|false}} for a 12-hour clock, and {{bcode|true}} for a 24-hour clock
:
class="wikitable" style="border: 4px solid #AAA; border-bottom: none; width: 500px; text-align: center;"
|+ Usage of dropDays and dropMonths ! dropDays !! dropMonths !! Days difference !! Displayed text | |||
colspan="4" style="background-color: #AAA;"| | |||
0 | 0 | 75 | 2 months, 14 days |
0 | 0 | 170 | 5 months, 18 days |
0 | 0 | 400 | 1 year, 1 month, 3 days |
0 | 0 | 800 | 2 years, 2 months, 7 days |
colspan="4" style="background-color: #AAA;"| | |||
93 | 0 | 75 | 75 days |
93 | 0 | 170 | 5 months |
93 | 0 | 400 | 1 year, 1 month |
93 | 0 | 800 | 2 years, 2 months |
colspan="4" style="background-color: #AAA;"| | |||
0 | 24 | 75 | 2 months, 14 days |
0 | 24 | 170 | 5 months, 18 days |
0 | 24 | 400 | 13 months, 3 days |
0 | 24 | 800 | 2 years |
colspan="4" style="background-color: #AAA;"| | |||
93 | 24 | 75 | 75 days |
93 | 24 | 170 | 5 months |
93 | 24 | 400 | 13 months |
93 | 24 | 800 | 2 years |
colspan="4" style="background-color: #AAA;"| |
=Settings for minimum display text=
To produce the smallest display text that still includes the date difference, copy the following code to your custom JavaScript file:
dateDifference: true,
dateFormat: 'dmy',
dayOfWeek: false,
dropDays: 93,
dropMonths: 24,
timeFirst: true,
twentyFourHours: true,
};
To produce the absolute smallest display text, suppress the date difference entirely by copying the following code to your custom JavaScript file:
dateDifference: false,
dateFormat: 'dmy',
dayOfWeek: false,
dropDays: 93,
dropMonths: 24,
timeFirst: true,
twentyFourHours: true,
};
=Style=
To change the timestamp's style, add the code below to your common.css page and modify it using Cascading Style Sheets. For example, to change the timestamp's size, increase or decrease the percentage in the code accordingly, such as to {{bcode|100%}} (it's set at 95% font size by default).
=Local time=
The script draws local time for signatures from the time set on the user's computer. The time for logs and page histories is drawn from the time set in the appearance tab in each user's preferences.
Localization
To use this script on another Wikipedia language, copy the code from comments in local time.js, and follow the instructions under LOCALIZING THIS SCRIPT
in the script's comments. The regular expression used to find timestamps may also need to be updated, on the line following document.querySelector('.mw-parser-output')
.
See also
- User:Mxn/CommentsInLocalTime – a replacement using Moment.js
- :id:Pengguna:William Surya Permana/comments in local time.js – Indonesian version of the script
{{script data | page = User:Gary/comments in local time.js | otherpage = no }}