From 050aa0bcea816ccd773ecf85e71f8c4eb7b18394 Mon Sep 17 00:00:00 2001 From: Neil Burrows Date: Fri, 10 Apr 2020 09:04:48 +0100 Subject: [PATCH] Display clock format in 12/24hr based on Roku Clock setting --- components/JFOverhang.brs | 29 +++++++++++++++------ components/collections/CollectionDetail.brs | 14 +--------- components/movies/MovieDetails.brs | 14 +--------- components/tvshows/TVListDetails.brs | 18 +------------ components/tvshows/TVListDetails.xml | 1 + components/tvshows/TVShowDescription.brs | 14 +--------- components/tvshows/TVShowDescription.xml | 1 + components/tvshows/TVShowDetails.brs | 14 +--------- source/utils/misc.brs | 27 +++++++++++++++++++ 9 files changed, 55 insertions(+), 77 deletions(-) diff --git a/components/JFOverhang.brs b/components/JFOverhang.brs index 6684a2ca..027843b4 100644 --- a/components/JFOverhang.brs +++ b/components/JFOverhang.brs @@ -15,6 +15,9 @@ sub init() optionStar.font.size = 58 overlayMeridian = m.top.findNode("overlayMeridian") overlayMeridian.font.size = 20 + ' get system preference clock format (12/24hr) + di = CreateObject("roDeviceInfo") + m.clockFormat = di.GetClockFormat() ' grab current time currentTime = CreateObject("roDateTime") currentTime.ToLocalTime() @@ -81,19 +84,29 @@ function updateTimeDisplay() overlayHours = m.top.findNode("overlayHours") overlayMinutes = m.top.findNode("overlayMinutes") overlayMeridian = m.top.findNode("overlayMeridian") - if m.currentHours < 12 then - overlayMeridian.text = "AM" - if m.currentHours = 0 then - overlayHours.text = "12" + + if m.clockFormat = "24h" then + overlayMeridian.text = "" + if m.currentHours < 10 then + overlayHours.text = "0" + StrI(m.currentHours).trim() else overlayHours.text = m.currentHours end if else - overlayMeridian.text = "PM" - if m.currentHours = 12 then - overlayHours.text = "12" + if m.currentHours < 12 then + overlayMeridian.text = "AM" + if m.currentHours = 0 then + overlayHours.text = "12" + else + overlayHours.text = m.currentHours + end if else - overlayHours.text = m.currentHours - 12 + overlayMeridian.text = "PM" + if m.currentHours = 12 then + overlayHours.text = "12" + else + overlayHours.text = m.currentHours - 12 + end if end if end if diff --git a/components/collections/CollectionDetail.brs b/components/collections/CollectionDetail.brs index a631b91b..a8d3185b 100644 --- a/components/collections/CollectionDetail.brs +++ b/components/collections/CollectionDetail.brs @@ -76,20 +76,8 @@ function getEndTime() as string duration_s = int(itemData.RunTimeTicks / 10000000.0) date.fromSeconds(date.asSeconds() + duration_s) date.toLocalTime() - hours = date.getHours() - meridian = "AM" - if hours = 0 - hours = 12 - meridian = "AM" - else if hours = 12 - hours = 12 - meridian = "PM" - else if hours > 12 - hours = hours - 12 - meridian = "PM" - end if - return Substitute("{0}:{1} {2}", stri(hours).trim(), leftPad(stri(date.getMinutes()).trim(), "0", 2), meridian) + return formatTime(date) end function sub setFavoriteColor() diff --git a/components/movies/MovieDetails.brs b/components/movies/MovieDetails.brs index 3ac62e35..26d2a857 100644 --- a/components/movies/MovieDetails.brs +++ b/components/movies/MovieDetails.brs @@ -96,20 +96,8 @@ function getEndTime() as string duration_s = int(itemData.RunTimeTicks / 10000000.0) date.fromSeconds(date.asSeconds() + duration_s) date.toLocalTime() - hours = date.getHours() - meridian = "AM" - if hours = 0 - hours = 12 - meridian = "AM" - else if hours = 12 - hours = 12 - meridian = "PM" - else if hours > 12 - hours = hours - 12 - meridian = "PM" - end if - return Substitute("{0}:{1} {2}", stri(hours).trim(), leftPad(stri(date.getMinutes()).trim(), "0", 2), meridian) + return formatTime(date) end function sub setFavoriteColor() diff --git a/components/tvshows/TVListDetails.brs b/components/tvshows/TVListDetails.brs index 47024030..9f15c346 100644 --- a/components/tvshows/TVListDetails.brs +++ b/components/tvshows/TVListDetails.brs @@ -41,22 +41,6 @@ function getEndTime() as string duration_s = int(itemData.RunTimeTicks / 10000000.0) date.fromSeconds(date.asSeconds() + duration_s) date.toLocalTime() - hours = date.getHours() - meridian = "AM" - if hours = 0 - hours = 12 - meridian = "AM" - else if hours = 12 - hours = 12 - meridian = "PM" - else if hours > 12 - hours = hours - 12 - meridian = "PM" - end if - minutes = stri(date.getMinutes()).trim() - if val(minutes) < 10 - minutes= "0" + minutes - end if - return Substitute("{0}:{1} {2}", stri(hours).trim(), minutes, meridian) + return formatTime(date) end function diff --git a/components/tvshows/TVListDetails.xml b/components/tvshows/TVListDetails.xml index d10e3ffe..dc2e0a63 100644 --- a/components/tvshows/TVListDetails.xml +++ b/components/tvshows/TVListDetails.xml @@ -25,4 +25,5 @@