- Posts: 25
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- Style css when an item from a category is written today
Style css when an item from a category is written today
- Slartibartfast
- Topic Author
- Offline
- Junior Member
Less
More
6 years 2 months ago - 6 years 2 months ago #168919
by Slartibartfast
Style css when an item from a category is written today was created by Slartibartfast
i am struggling for months with this thing. so i am starting from the beginning
i have a side menu with items to different categories.
each category may or may not have an article/item written per day. not more than one though.
So, i wan to show a "new" -icon/gif whatever- next to the menu item of each category that has a new article written today.
i have managed to do it by:
- creating a custom template in my_theme/html/mod_menu
- using the publish_up field of the jos_k2_items table.
but because my timezone is +3 hours to UTC the article must be written after 3am ...
my server time is UTC. this cannot be changed
my joomla timezone is set to Europe/Athens
K2 stores UTC time in publish_up field
here is my query, but i start to believe that i need a completely different approach
any ideas would be much appreciated :)
i have a side menu with items to different categories.
each category may or may not have an article/item written per day. not more than one though.
So, i wan to show a "new" -icon/gif whatever- next to the menu item of each category that has a new article written today.
i have managed to do it by:
- creating a custom template in my_theme/html/mod_menu
- using the publish_up field of the jos_k2_items table.
but because my timezone is +3 hours to UTC the article must be written after 3am ...
my server time is UTC. this cannot be changed
my joomla timezone is set to Europe/Athens
K2 stores UTC time in publish_up field
here is my query, but i start to believe that i need a completely different approach
$nowdate = JFactory::getDate('now', new DateTimeZone('Europe/Athens'));
$curdate = JFactory::getDate('now', new DateTimeZone('Europe/Athens'))->format('Y-m-d', TRUE);
$query->select("distinct ". $db->quoteName('catid'));
$query->from($db->quoteName('*****_k2_items'));
$query->where($db->quoteName('publish_up') .' <= '. $db->quote( $nowdate ));
$query->where('Date('.$db->quoteName('publish_up').')' . ' = '. $db->quote( $curdate ));
$query->where($db->quoteName('published') .' = 1');
$query->where($db->quoteName('trash') .' = 0');
$query->order('id ASC');
any ideas would be much appreciated :)
Last edit: 6 years 2 months ago by Slartibartfast.
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
6 years 2 months ago #168922
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Style css when an item from a category is written today
There is no need to query the database for this.
You can just use the item creation/modified date and compare it with the current time. I would go even further and use JS to compare the time with the user's actual timezone.
I'm guessing you probably know your way around PHP and JS, so just grab the $item->created or $item->modified date (UTC) and print it as a data-attribute (e.g. data-created="2018-08-31") in the item's title or container. Then use JS to read all the data attributes, compare them to the user's actual time and if the difference is less than say 24 hrs, apply a new class dynamically which will show a <span> element that contains the word "New" (or some image).
You can just use the item creation/modified date and compare it with the current time. I would go even further and use JS to compare the time with the user's actual timezone.
I'm guessing you probably know your way around PHP and JS, so just grab the $item->created or $item->modified date (UTC) and print it as a data-attribute (e.g. data-created="2018-08-31") in the item's title or container. Then use JS to read all the data attributes, compare them to the user's actual time and if the difference is less than say 24 hrs, apply a new class dynamically which will show a <span> element that contains the word "New" (or some image).
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Slartibartfast
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
6 years 2 months ago #168925
by Slartibartfast
Replied by Slartibartfast on topic Style css when an item from a category is written today
Thank you for your reply!
well unfortunately i am more of a "other people's code editor". So i am not sure i follow your thinking. i have 8 menu items, which equals 8 categories equals 8 possible "spans"
so am i suppose to code the mod_menu as before?
and second, how am i going to grab the data attributes of the item's container when i am in the home page?
Obviously i lost you there
it would be great help for me if you could specify your thinking a little bit more. then i could search my way out of this :)
well unfortunately i am more of a "other people's code editor". So i am not sure i follow your thinking. i have 8 menu items, which equals 8 categories equals 8 possible "spans"
so am i suppose to code the mod_menu as before?
and second, how am i going to grab the data attributes of the item's container when i am in the home page?
Obviously i lost you there
it would be great help for me if you could specify your thinking a little bit more. then i could search my way out of this :)
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
6 years 2 months ago - 6 years 2 months ago #168928
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Style css when an item from a category is written today
I think I misread your original post, sorry...
Try removing ", new DateTimeZone('Europe/Athens')" from your $now & $cur variables. Change the timezone in Joomla's global config to match your timezone. And you should be fine in regards to timezone differences, because these 2 variables always return the server's time values, not the user's (from their browser). That should work.
Try removing ", new DateTimeZone('Europe/Athens')" from your $now & $cur variables. Change the timezone in Joomla's global config to match your timezone. And you should be fine in regards to timezone differences, because these 2 variables always return the server's time values, not the user's (from their browser). That should work.
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Last edit: 6 years 2 months ago by JoomlaWorks.
Please Log in or Create an account to join the conversation.
- Slartibartfast
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
6 years 2 months ago #168929
by Slartibartfast
Replied by Slartibartfast on topic Style css when an item from a category is written today
thank you for your answer.
- changed to JFactory::getDate('now');
- in global configuration the timezone is already "Athens"
still echo $curdate; and echo $nowdate; are returning UTC while JFactory::getDate('now', new DateTimeZone('Europe/Athens')); returns the correct time
i think that the problem is at the field "jos_k2_items". if i write an article at 2am on September 2nd, the field stores 23:00 01/09/2018 cause it stores UTC.
so when this is compared with the current date (02/09/2018) it obviously does not show the <span> since it "thinks" that the article was written yesterday.
- changed to JFactory::getDate('now');
- in global configuration the timezone is already "Athens"
still echo $curdate; and echo $nowdate; are returning UTC while JFactory::getDate('now', new DateTimeZone('Europe/Athens')); returns the correct time
i think that the problem is at the field "jos_k2_items". if i write an article at 2am on September 2nd, the field stores 23:00 01/09/2018 cause it stores UTC.
so when this is compared with the current date (02/09/2018) it obviously does not show the <span> since it "thinks" that the article was written yesterday.
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
6 years 2 months ago #168930
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Style css when an item from a category is written today
After 9+ years, I believe we'd have notice such a bug.
The problem is clearly in Joomla or some server configuration that you can't get the offset. But you can change that if you want manually, see here: docs.joomla.org/How_to_use_JDate
Or change the offset like this: joomla.stackexchange.com/a/4762/7022
You have 2 ways. Keep in mind that for Greece you need to adjust for DST (daylight saving time) as Joomla's offset will return +2 when it's currently +3.
But fear not! Our troubles may soon come to an end: www.theguardian.com/world/2018/aug/31/eu-recommend-member-states-abolish-daylight-saving-time
The problem is clearly in Joomla or some server configuration that you can't get the offset. But you can change that if you want manually, see here: docs.joomla.org/How_to_use_JDate
Or change the offset like this: joomla.stackexchange.com/a/4762/7022
You have 2 ways. Keep in mind that for Greece you need to adjust for DST (daylight saving time) as Joomla's offset will return +2 when it's currently +3.
But fear not! Our troubles may soon come to an end: www.theguardian.com/world/2018/aug/31/eu-recommend-member-states-abolish-daylight-saving-time
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Slartibartfast
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
6 years 2 months ago #168931
by Slartibartfast
Replied by Slartibartfast on topic Style css when an item from a category is written today
no no, you misunderstood me.
i meant that as a problem for my code not a k2 problem ;)
But still, after you last post, if i understand correctly, you suggest that the date saved in jos_k2_items publish_up field should be saved in the timezone set in the global configuration? in my case Athens.
If that is the case then why my joomla/k2 installation saves in UTC?
and again just to clarify:
i have an article with publish_up date 2018-09-03 03:03 (Athens)
in the database the field is saved in UTC 2018-09-00 03:03
as for the daylight-saving ... if you like John Oliver check this
i meant that as a problem for my code not a k2 problem ;)
But still, after you last post, if i understand correctly, you suggest that the date saved in jos_k2_items publish_up field should be saved in the timezone set in the global configuration? in my case Athens.
If that is the case then why my joomla/k2 installation saves in UTC?
and again just to clarify:
i have an article with publish_up date 2018-09-03 03:03 (Athens)
in the database the field is saved in UTC 2018-09-00 03:03
as for the daylight-saving ... if you like John Oliver check this
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
6 years 2 months ago #168937
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Style css when an item from a category is written today
No, times are saved as UTC and that's the reasonable thing to do. Maybe a year later you'll move your site elsewhere (cause you physically moved) and decide to update the time offset.
Joomla does the job of converting UTC times to local times when content is displayed and any component is using the Joomla date functions to parse dates from the DB (like K2 does).
Joomla does the job of converting UTC times to local times when content is displayed and any component is using the Joomla date functions to parse dates from the DB (like K2 does).
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Slartibartfast
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
6 years 2 months ago #168942
by Slartibartfast
Replied by Slartibartfast on topic Style css when an item from a category is written today
ok,. completely understood. so we are back to square one :)
how can i convert "publish_up" from UTC to my timezone(EEST ot EET) so the below query does not compare different timezones like it does now (UTC <= EEST):
how can i convert "publish_up" from UTC to my timezone(EEST ot EET) so the below query does not compare different timezones like it does now (UTC <= EEST):
$query->where($db->quoteName('publish_up') .' <= '. $db->quote( $nowdate ));
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
6 years 2 months ago #168969
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Style css when an item from a category is written today
Do the opposite, this is what I'm saying. Leave the DB times as is and then simply offset the output by using JDate. If an author adds an article on 2am GR time, this means the UTC timestamp is 23pm of the previous day.
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Forum
- K2 Community Forum
- English K2 Community
- Style css when an item from a category is written today