Allow to select whether to view time as 12-hour time or 24-hour time 
via http://www.dreamwidth.org/manage/settings/?cat=display. This will respect 
the viewer's preferences in sitescheme pages, and whenever the journal owner 
has not customized the time for their journal.

        Patch by yvi. 

diffs (456 lines):

diff -r 095f6506596c -r e1f39e724a18 bin/upgrading/en.dat
--- a/bin/upgrading/en.dat      Wed Jun 02 17:50:33 2010 +0800
+++ b/bin/upgrading/en.dat      Wed Jun 02 18:48:11 2010 +0800
@@ -2783,6 +2783,14 @@ setting.synlevel.option.select.summary=B
 
 setting.synlevel.option.select.title=Title Only
 
+setting.timeformat.label=Time display format
+
+setting.timeformat.option.12hour=12 Hour (am/pm)
+
+setting.timeformat.option.24hour=24 Hour
+
+setting.timeformat.error.invalid=Invalid time format
+
 setting.txtmsgsetup.details=(<a [[aopts]]>details</a>)
 
 setting.txtmsgsetup.error.notsecured=Information will not be saved if you 
don't allow anyone to send you messages.
diff -r 095f6506596c -r e1f39e724a18 bin/upgrading/proplists.dat
--- a/bin/upgrading/proplists.dat       Wed Jun 02 17:50:33 2010 +0800
+++ b/bin/upgrading/proplists.dat       Wed Jun 02 18:48:11 2010 +0800
@@ -1038,6 +1038,14 @@ userproplist.stylesys:
   multihomed: 0
   prettyname: Style System to use
 
+userproplist.timeformat_24:
+  cldversion: 4
+  datatype: bool
+  des: use 24-hour time format on site
+  indexed: 0
+  multihomed: 0
+  prettyname: 24-hour time format
+
 userproplist.theme_preview_styleid:
   cldversion: 4
   datatype: num
diff -r 095f6506596c -r e1f39e724a18 bin/upgrading/s2layers/core1.s2
--- a/bin/upgrading/s2layers/core1.s2   Wed Jun 02 17:50:33 2010 +0800
+++ b/bin/upgrading/s2layers/core1.s2   Wed Jun 02 18:48:11 2010 +0800
@@ -304,6 +304,7 @@ class EntryLite
 
     var DateTime time "The user-specified time of the post, or the GMT time if 
it's a comment.";
     var DateTime system_time "The system time (in GMT) this entry or comment 
was posted.";
+    var bool timeformat24 "Indicates that the time should be displayed in 
24-hour format";
 
     var UserLite poster "Author of the entry, or null if an anonymous comment";
     var UserLite journal "Journal the entry has been posted to";
@@ -487,6 +488,9 @@ class Page
 
     var readonly DateTime time
     "A DateTime object filled with the time (GMT) when the page was created.";
+
+    var bool timeformat24 
+    "Indicates that the time should be displayed in 24-hour format";
 
     var Link{} data_link "Links to various machine-readable data sources 
relating to this page";
     var string[] data_links_order "An array of data views which can be used to 
order the data_link hash";
@@ -972,6 +976,12 @@ property string lang_fmt_time_short {
     des = "Time format.";
 }
 set lang_fmt_time_short = "%%hh%%:%%min%% %%a%%m";
+
+property string lang_fmt_time_short_24 {
+    noui = 1;
+    des = "Time format (24-hour).";
+}
+set lang_fmt_time_short = "%%HH%%:%%min%%";
 
 property string lang_fmt_month_short {
     noui = 1;
@@ -2378,7 +2388,11 @@ function EntryLite::time_display(string 
         $datefmt = "med";
     }
     if ($timefmt == "") {
-        $timefmt = "short";
+        if ($this.timeformat24) {
+            $timefmt = "short_24";
+        } else {
+            $timefmt = "short";
+        }
     }
 
     var string ret;
@@ -2399,7 +2413,11 @@ function Comment::time_display (string d
         $datefmt = "iso";
     }
     if ($timefmt == "") {
-        $timefmt = "short";
+        if ($this.timeformat24) {
+            $timefmt = "short_24";
+        } else {
+            $timefmt = "short";
+        }
     }
 
     var string tooltip = "";
diff -r 095f6506596c -r e1f39e724a18 bin/upgrading/s2layers/core2.s2
--- a/bin/upgrading/s2layers/core2.s2   Wed Jun 02 17:50:33 2010 +0800
+++ b/bin/upgrading/s2layers/core2.s2   Wed Jun 02 18:48:11 2010 +0800
@@ -322,6 +322,7 @@ class EntryLite
 
     var DateTime time "The user-specified time of the post, or the GMT time if 
it's a comment.";
     var DateTime system_time "The system time (in GMT) this entry or comment 
was posted.";
+    var readonly bool timeformat24 "Indicates whether the time should be 
displayed in 24-hour format";
 
     var UserLite poster "Author of the entry, or null if an anonymous comment";
     var UserLite journal "Journal the entry has been posted to";
@@ -531,6 +532,9 @@ class Page
     var readonly Entry[] activeentries
     "Array of recently active entries available to be seen by the viewer of 
the page.";
 
+    var readonly bool timeformat24 
+    "Indicates whether the time should be displayed in 24-hour format";
+
     var readonly DateTime local_time
     "A DateTime object filled with the time (in the viewer's timezone) when 
the page was created.";
 
@@ -2639,6 +2643,8 @@ property string lang_fmt_date_long_day {
 
 property string lang_fmt_time_short { noui = 1; des = "Time format."; }
 
+property string lang_fmt_time_short_24 { noui = 1; des = "Time format (24 
hours)."; }
+
 property string lang_fmt_month_short { noui = 1; des = "Short month format."; }
 
 property string lang_fmt_month_med { noui = 1; des = "Medium month format."; }
@@ -2651,6 +2657,7 @@ set lang_fmt_date_long = "%%month%% %%da
 set lang_fmt_date_long = "%%month%% %%dayord%%, %%yyyy%%";
 set lang_fmt_date_long_day = "%%day%%, %%month%% %%dayord%%, %%yyyy%%";
 set lang_fmt_time_short = "%%hh%%:%%min%% %%a%%m";
+set lang_fmt_time_short_24 = "%%HH%%:%%min%%";
 set lang_fmt_month_short = "%%m%%/%%yy%%";
 set lang_fmt_month_med = "%%mon%% %%yyyy%%";
 set lang_fmt_month_long = "%%month%% %%yyyy%%";
@@ -4057,7 +4064,11 @@ function Page::print_time(string datefmt
         $datefmt = "med";
     }
     if ($timefmt == "") {
-        $timefmt = "short";
+        if ($this.timeformat24) {
+            $timefmt = "short_24";
+        } else {
+            $timefmt = "short";
+        }
     }
 
     var string ret;
@@ -4616,7 +4627,11 @@ function EntryLite::time_display(string 
         $datefmt = "med";
     }
     if ($timefmt == "") {
-        $timefmt = "short";
+        if ($this.timeformat24) {
+            $timefmt = "short_24";
+        } else {
+            $timefmt = "short";
+        }
     }
 
     var string ret;
@@ -4636,7 +4651,11 @@ function Entry::time_display(string date
         $datefmt = "med";
     }
     if ($timefmt == "") {
-        $timefmt = "short";
+        if ($this.timeformat24) {
+            $timefmt = "short_24";
+        } else {
+            $timefmt = "short";
+        }
     }
 
     var string ret;
@@ -4662,7 +4681,11 @@ function Comment::time_display (string d
         $datefmt = "iso";
     }
     if ($timefmt == "") {
-        $timefmt = "short";
+        if ($this.timeformat24) {
+            $timefmt = "short_24";
+        } else {
+            $timefmt = "short";
+        }
     }
 
     var string tooltip = "";
@@ -4950,7 +4973,11 @@ function MonthDay::print_subjectlist() {
     # Too many tables...
     var Page p = get_page();
     foreach var Entry e ($.entries) {
-        $e->print_time("none", "short");
+        if ($p.timeformat24) {
+            $e->print_time("none", "short_24");
+        } else {
+            $e->print_time("none", "short");
+        }
         $e->print_poster();
         $e->print_metatypes();
         $e->print_subject();
diff -r 095f6506596c -r e1f39e724a18 bin/upgrading/s2layers/zesty/layout.s2
--- a/bin/upgrading/s2layers/zesty/layout.s2    Wed Jun 02 17:50:33 2010 +0800
+++ b/bin/upgrading/s2layers/zesty/layout.s2    Wed Jun 02 18:48:11 2010 +0800
@@ -239,6 +239,12 @@ propgroup Text {
     }
         set posted_time_format = "%%hh%%:%%min%%%%a%%m";
 
+    property string posted_time_format_24 {
+        noui = 1;
+        des = "[time] format for from 'posted by [poster] at [time] ...'";
+    }
+        set posted_time_format_24 = "%%HH%%:%%min%%";
+
     property string posted_date_format {
         noui = 1;
         des = "[date] format for 'posted by [poster] at [time] on [date] ...'";
@@ -1130,13 +1136,20 @@ function Page::lay_print_posted_by(Entry
     var string format;
     var string[] args;
     var string tags;
+    var string timeformat;
+
+    if ($this.timeformat24) {
+        $timeformat = $*posted_time_format_24;
+    } else {
+        $timeformat = $*posted_time_format;
+    }
 
     # default: "posted by %1 at %2 on %3";
     $format = $*posted_by_at_on;
 
     $args = [
           $this->lay_get_poster($e),
-          $e.time->date_format( $*posted_time_format ),
+          $e.time->date_format( $timeformat ),
           $e.time->date_format( $*posted_date_format )
           ];
 
diff -r 095f6506596c -r e1f39e724a18 cgi-bin/DW/Setting/TimeFormat.pm
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/DW/Setting/TimeFormat.pm  Wed Jun 02 18:48:11 2010 +0800
@@ -0,0 +1,78 @@
+#!/usr/bin/perl
+##
+## DW::Setting::TimeFormat
+##
+## DW::Setting module for choosing whether time stamps on entry pages and 
journals should appear
+## in 24-hour or 12-hour time format
+##
+## Authors:
+##      Rebecca Freiburg <[email protected]>
+##
+## Copyright (c) 2010 by Dreamwidth Studios, LLC.
+##
+## This program is free software; you may redistribute it and/or modify it 
under
+## the same terms as Perl itself.  For a copy of the license, please reference
+## 'perldoc perlartistic' or 'perldoc perlgpl'.
+##
+
+package DW::Setting::TimeFormat;
+use base 'LJ::Setting';
+use strict;
+use warnings;
+
+sub should_render {
+    $_[1] ? 1 : 0;
+}
+
+sub label {
+    $_[0]->ml( 'setting.timeformat.label' );
+}
+
+sub option {
+    my ( $class, $u, $errs, $args ) = @_;
+
+    my $key = $class->pkgkey;
+    my $ret;
+    my $timeformat_24 = $errs ? $class->get_arg( $args, "timeformat_24" ) : 
$u->prop( "timeformat_24" ); 
+
+    $ret .= LJ::html_check( {
+        type => "radio",
+        name => "${key}timeformat",
+        id => "${key}timeformat_12",
+        value => 0,
+        selected => !$timeformat_24,
+    } );
+    $ret .= "<label for='${key}timeformat_12' class='radiotext'>" . 
$class->ml( 'setting.timeformat.option.12hour' ) . "</label>";
+    $ret .= LJ::html_check( {
+        type => "radio",
+        name => "${key}timeformat",
+        id => "${key}timeformat_24",
+        value => 1,
+        selected => $timeformat_24,
+    } );
+    $ret .= "<label for='${key}timeformat_24' class='radiotext'>" . 
$class->ml('setting.timeformat.option.24hour') . "</label>";
+
+    return $ret;
+
+}
+
+sub error_check {
+    my ( $class, $u, $args ) = @_;
+    my $val = $class->get_arg( $args, "timeformat" );
+
+    $class->errors( timeformat => $class->ml( 
'setting.timeformat.error.invalid' ) )
+        unless $val =~ /^[01]$/;
+
+    return 1;
+}
+
+sub save {
+    my ( $class, $u, $args ) = @_;
+
+    my $val = $class->get_arg( $args, "timeformat" ) || 0;
+    $u->set_prop( "timeformat_24" => $val );
+
+    return 1;
+}
+
+1;
diff -r 095f6506596c -r e1f39e724a18 cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm  Wed Jun 02 17:50:33 2010 +0800
+++ b/cgi-bin/LJ/S2.pm  Wed Jun 02 18:48:11 2010 +0800
@@ -1786,8 +1786,8 @@ sub Entry
         'link_keyseq' => [ 'edit_entry', 'edit_tags' ],
         'metadata' => {},
     };
-    foreach (qw(subject text journal poster new_day end_day
-                comments userpic permalink_url itemid tags)) {
+    foreach ( qw( subject text journal poster new_day end_day
+                comments userpic permalink_url itemid tags timeformat24 ) ) {
         $e->{$_} = $arg->{$_};
     }
 
@@ -2009,7 +2009,8 @@ sub Entry_from_entryobj
         userpic => $userpic,
         tags => $taglist,
         permalink_url => $entry_obj->url,
-        moodthemeid => $moodthemeid
+        moodthemeid => $moodthemeid,
+        timeformat24 => $remote && $remote->use_24hour_time
         } );
 
     return $entry;
@@ -2094,6 +2095,7 @@ sub Page
         'data_link' => {},
         'data_links_order' => [],
         '_styleopts' => \%{ LJ::viewing_style_opts( %$get ) },
+        timeformat24 => $remote && $remote->use_24hour_time
     };
 
     if ($LJ::UNICODE && $opts && $opts->{'saycharset'}) {
diff -r 095f6506596c -r e1f39e724a18 cgi-bin/LJ/S2/EntryPage.pm
--- a/cgi-bin/LJ/S2/EntryPage.pm        Wed Jun 02 17:50:33 2010 +0800
+++ b/cgi-bin/LJ/S2/EntryPage.pm        Wed Jun 02 18:48:11 2010 +0800
@@ -273,6 +273,7 @@ sub EntryPage
                 'edittime_remote' => $edittime_remote,
                 'edittime_poster' => $edittime_poster,
                 'edit_url' => $edit_url,
+                timeformat24 => $remote && $remote->use_24hour_time,
             };
 
             # don't show info from suspended users
@@ -509,6 +510,7 @@ sub EntryPage_entry
         end_day => 0,
         userpic => $userpic,
         permalink_url => $entry->url,
+        timeformat24 => $remote && $remote->use_24hour_time,
     } );
 
     return ($entry, $s2entry);
diff -r 095f6506596c -r e1f39e724a18 cgi-bin/LJ/S2/MonthPage.pm
--- a/cgi-bin/LJ/S2/MonthPage.pm        Wed Jun 02 17:50:33 2010 +0800
+++ b/cgi-bin/LJ/S2/MonthPage.pm        Wed Jun 02 18:48:11 2010 +0800
@@ -27,6 +27,7 @@ sub MonthPage
     $p->{'_type'} = "MonthPage";
     $p->{'view'} = "month";
     $p->{'days'} = [];
+    $p->{timeformat24} = $remote && $remote->use_24hour_time;
 
     my $ctx = $opts->{'ctx'};
 
diff -r 095f6506596c -r e1f39e724a18 cgi-bin/LJ/S2/ReplyPage.pm
--- a/cgi-bin/LJ/S2/ReplyPage.pm        Wed Jun 02 17:50:33 2010 +0800
+++ b/cgi-bin/LJ/S2/ReplyPage.pm        Wed Jun 02 18:48:11 2010 +0800
@@ -212,6 +212,7 @@ sub ReplyPage
             'frozen' => $parpost->{'state'} eq "F" ? 1 : 0,
             'deleted' => $parpost->{'state'} eq "D" ? 1 : 0,
             'full' => 1,
+            timeformat24 => $remote && $remote->use_24hour_time,
         };
 
         # Conditionally add more links to the keyseq
diff -r 095f6506596c -r e1f39e724a18 cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm        Wed Jun 02 17:50:33 2010 +0800
+++ b/cgi-bin/LJ/User.pm        Wed Jun 02 18:48:11 2010 +0800
@@ -2716,6 +2716,9 @@ sub get_sticky_entry {
     return undef;
 }
 
+# should times be displayed in 24-hour time format?
+sub use_24hour_time { $_[0]->prop( 'timeformat_24' ) ? 1 : 0; }
+
 sub _lazy_migrate_infoshow {
     my ($u) = @_;
     return 1 unless LJ::is_enabled('infoshow_migrate');
diff -r 095f6506596c -r e1f39e724a18 htdocs/manage/settings/index.bml
--- a/htdocs/manage/settings/index.bml  Wed Jun 02 17:50:33 2010 +0800
+++ b/htdocs/manage/settings/index.bml  Wed Jun 02 18:48:11 2010 +0800
@@ -75,6 +75,7 @@ body<=
                 DW::Setting::CutInbox
                 LJ::Setting::EmailFormat
                 LJ::Setting::EntryEditor
+                DW::Setting::TimeFormat
                 LJ::Setting::NCTalkLinks
                 LJ::Setting::StyleMine
                 LJ::Setting::NavStrip
diff -r 095f6506596c -r e1f39e724a18 htdocs/talkread.bml
--- a/htdocs/talkread.bml       Wed Jun 02 17:50:33 2010 +0800
+++ b/htdocs/talkread.bml       Wed Jun 02 18:48:11 2010 +0800
@@ -155,7 +155,7 @@ body<=
     my $remote = LJ::get_remote();
 
     my $tz_remote;
-    my $s2_ctx = [];  # ghetto fake S2 context object
+    my $s2_ctx = [];  # fake S2 context object
     if ($remote) {
         my $tz = $remote->prop("timezone");
         $tz_remote = $tz ? eval { DateTime::TimeZone->new( name => $tz); } : 
undef;
@@ -280,7 +280,18 @@ body<=
                                                 'userlink' => LJ::ljuser($up) 
});
     }
 
-    my $etime = $item->{'eventtime'};
+    my $fmt_time_short;
+    if ( $remote && $remote->use_24hour_time ) {
+        $fmt_time_short = "%%HH%%:%%min%%";
+    } else {
+        $fmt_time_short = "%%hh%%:%%min%% %%a%%m";
+    }
+
+    my $etime = $item->{eventtime};
+    $etime = LJ::mysqldate_to_time( $etime );
+    $etime = LJ::S2::DateTime_unix( $etime );
+    $etime = S2::Builtin::LJ::Date__date_format( $s2_ctx, $etime, "iso" ) .
+            " " . S2::Builtin::LJ::DateTime__time_format( $s2_ctx, $etime, 
$fmt_time_short );
     $etime =~ s!(\d\d\d\d)-(\d\d)-(\d\d)!LJ::date_to_view_links($u, $&)!e;
     $ret .= "<br /><span class='time'>@ $etime</span>";
     $ret .= "</td></tr></table>";
@@ -461,7 +472,6 @@ body<=
     $LJ_cmtinfo{'canAdmin'} = LJ::can_manage($remote, $u) ? 1 : 0;
     $LJ_cmtinfo{'canSpam'} = LJ::sysban_check( 'spamreport', $u->user ) ? 0 : 
1;
     $LJ_cmtinfo{'remote'} = $remote ? $remote->{user} : "";
-    my $fmt_time_short = "%%hh%%:%%min%% %%a%%m";
     my $show_thread_expander = $u->show_thread_expander( $remote );
 
     #
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to