Clean up date format stuff

This commit is contained in:
swaggboi 2022-08-22 01:24:34 -04:00
parent b925f5c118
commit bf5a320e3e
3 changed files with 38 additions and 39 deletions

View File

@ -27,4 +27,3 @@ Run the tests locally (against development environment)
1. Reply model needs to become Remark (to fix the error handling stuff) 1. Reply model needs to become Remark (to fix the error handling stuff)
1. Add hyperlink somewhere to single thread view (whoopsie) 1. Add hyperlink somewhere to single thread view (whoopsie)
1. Paging for replies in single thread view 1. Paging for replies in single thread view
1. Pick a date format

View File

@ -9,14 +9,17 @@ has 'pg';
sub new($class, $pg, $pg_reference) { sub new($class, $pg, $pg_reference) {
bless { bless {
$pg => $pg_reference, $pg => $pg_reference,
replies_per_page => 5 replies_per_page => 5,
date_format => 'Dy Mon FMDD FMHH24:MI TZ YYYY'
}, $class }, $class
} }
sub get_replies_by_thread_id($self, $thread_id) { sub get_replies_by_thread_id($self, $thread_id) {
$self->pg->db->query(<<~'END_SQL', $thread_id)->hashes() my $date_format = %$self{'date_format'};
$self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hashes();
SELECT reply_id AS id, SELECT reply_id AS id,
TO_CHAR(reply_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY') AS date, TO_CHAR(reply_date, ?) AS date,
reply_author AS author, reply_author AS author,
reply_body AS body reply_body AS body
FROM replies FROM replies
@ -26,8 +29,4 @@ sub get_replies_by_thread_id($self, $thread_id) {
END_SQL END_SQL
} }
#sub exception($self, $exception) {
# say $exception
#}
1; 1;

View File

@ -9,7 +9,8 @@ has 'pg';
sub new($class, $pg, $pg_reference) { sub new($class, $pg, $pg_reference) {
bless { bless {
$pg => $pg_reference, $pg => $pg_reference,
threads_per_page => 5 threads_per_page => 5,
date_format => 'Dy Mon FMDD FMHH24:MI TZ YYYY'
}, $class }, $class
} }
@ -29,9 +30,9 @@ sub create_thread($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
} }
sub get_all_threads($self) { sub get_all_threads($self) {
$self->pg->db->query(<<~'END_SQL')->hashes() $self->pg->db->query(<<~'END_SQL', %$self{'date_format'})->hashes()
SELECT thread_id AS id, SELECT thread_id AS id,
TO_CHAR(thread_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY') AS date, TO_CHAR(thread_date, ?) AS date,
thread_author AS author, thread_author AS author,
thread_title AS title, thread_title AS title,
thread_body AS body thread_body AS body
@ -42,12 +43,14 @@ sub get_all_threads($self) {
} }
sub get_threads_by_page($self, $this_page = 1) { sub get_threads_by_page($self, $this_page = 1) {
my $date_format = %$self{'date_format'};
my $row_count = $self->{'threads_per_page'}; my $row_count = $self->{'threads_per_page'};
my $offset = ($this_page - 1) * $row_count; my $offset = ($this_page - 1) * $row_count;
$self->pg->db->query(<<~'END_SQL', $row_count, $offset)->hashes(); $self->pg->db
->query(<<~'END_SQL', $date_format, $row_count, $offset)->hashes();
SELECT thread_id AS id, SELECT thread_id AS id,
TO_CHAR(thread_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY') AS date, TO_CHAR(thread_date, ?) AS date,
thread_author AS author, thread_author AS author,
thread_title AS title, thread_title AS title,
thread_body AS body thread_body AS body
@ -81,9 +84,11 @@ sub get_thread_count($self) {
} }
sub get_thread_by_id($self, $thread_id) { sub get_thread_by_id($self, $thread_id) {
$self->pg->db->query(<<~'END_SQL', $thread_id)->hashes->[0] my $date_format = %$self{'date_format'};
$self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hash();
SELECT thread_id AS id, SELECT thread_id AS id,
TO_CHAR(thread_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY') AS date, TO_CHAR(thread_date, ?) AS date,
thread_author AS author, thread_author AS author,
thread_title AS title, thread_title AS title,
thread_body AS body thread_body AS body
@ -92,8 +97,4 @@ sub get_thread_by_id($self, $thread_id) {
END_SQL END_SQL
} }
#sub exception($self, $exception) {
# say $exception
#}
1; 1;