From 5becf260fafd741fd34948f12131d8074dc2b5dc Mon Sep 17 00:00:00 2001 From: lizyn Date: Tue, 25 Dec 2018 15:31:44 +0800 Subject: fix incorrect reading time calculation for entries with CJK characters --- src/Wallabag/CoreBundle/Tools/Utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Tools/Utils.php b/src/Wallabag/CoreBundle/Tools/Utils.php index 46bb1dc5..0a805210 100644 --- a/src/Wallabag/CoreBundle/Tools/Utils.php +++ b/src/Wallabag/CoreBundle/Tools/Utils.php @@ -29,6 +29,6 @@ class Utils */ public static function getReadingTime($text) { - return floor(\count(preg_split('~[^\p{L}\p{N}\']+~u', strip_tags($text))) / 200); + return floor(\count(preg_split('~([^\p{L}\p{N}\']+|\p{Han}|\p{Hiragana}|\p{Katakana}|\p{Hangul})~u', strip_tags($text))) / 200); } } -- cgit v1.2.3 From 35983eb9bbbf78041ff9f6679ca345850f41c5f1 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 4 Jan 2019 11:22:43 +0100 Subject: Improve reading time tests --- src/Wallabag/CoreBundle/Tools/Utils.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Tools/Utils.php b/src/Wallabag/CoreBundle/Tools/Utils.php index 0a805210..c14d2aa0 100644 --- a/src/Wallabag/CoreBundle/Tools/Utils.php +++ b/src/Wallabag/CoreBundle/Tools/Utils.php @@ -20,10 +20,9 @@ class Utils } /** - * For a given text, we calculate reading time for an article - * based on 200 words per minute. + * For a given text, we calculate reading time for an article based on 200 words per minute. * - * @param $text + * @param string $text * * @return float */ -- cgit v1.2.3 From 7f8630b91c1ef0a650bfe7cf422126187eb3c8f2 Mon Sep 17 00:00:00 2001 From: lizyn Date: Sat, 5 Jan 2019 12:30:15 +0800 Subject: Counting two characters together as a word in CJK --- src/Wallabag/CoreBundle/Tools/Utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Tools/Utils.php b/src/Wallabag/CoreBundle/Tools/Utils.php index c14d2aa0..e56e251e 100644 --- a/src/Wallabag/CoreBundle/Tools/Utils.php +++ b/src/Wallabag/CoreBundle/Tools/Utils.php @@ -28,6 +28,6 @@ class Utils */ public static function getReadingTime($text) { - return floor(\count(preg_split('~([^\p{L}\p{N}\']+|\p{Han}|\p{Hiragana}|\p{Katakana}|\p{Hangul})~u', strip_tags($text))) / 200); + return floor(\count(preg_split('~([^\p{L}\p{N}\']+|(\p{Han}|\p{Hiragana}|\p{Katakana}|\p{Hangul}){1,2})~u', strip_tags($text))) / 200); } } -- cgit v1.2.3