inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Aug 17, 2015 22:40:24 GMT -8
So I'm looking for a way to auto place in the season and year. The season should change each month on a eight month cycle - eg
Year 1 - Spring (2 months) Year 1 - Summer (2 months) Year 1 - Autumn (2 months) Year 1 - Winter (2 months) Year 2 - Spring (2 months) Year 2 - Summer (2 months) Year 2 - Autumn (2 months) Year 2 - Winter (2 months)
etc where after each series of four seasons the year number is incremented by one.
It should be writable to a div, any ideas?
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Aug 19, 2015 1:06:05 GMT -8
Bump - I think I can work out the theory for this just not the code. I'm theorising that the year will be stored as a variable and an if statement would be used to check how many months have passed. For ease of use a month will likely be defined as 30 and a check in pace to count how many 30 days have passed. Once it gets to 6x30 (180 days in this case I do believe) then a year count will be incremented by one. Every 60 days a new season would be implemented and I'm guessing seasons would be stored in an array. Im just not sure how to fit this all together
|
|
inherit
220772
0
Mar 24, 2023 21:43:23 GMT -8
Tiffy-Bean
I support plugin and theme makers rights to create themes and plugins that are paid for.
1,052
April 2015
tiffythecodingwhiz
|
Post by Tiffy-Bean on Aug 19, 2015 9:23:10 GMT -8
I would think this could be done very similar to auto updating the copyright. Doing some tests myself but if anyone knows how, feel free to jump in (cause there are many on this site who are by far more experienced then I am). I'm interested in this as well!
|
|
inherit
220772
0
Mar 24, 2023 21:43:23 GMT -8
Tiffy-Bean
I support plugin and theme makers rights to create themes and plugins that are paid for.
1,052
April 2015
tiffythecodingwhiz
|
Post by Tiffy-Bean on Aug 19, 2015 12:31:10 GMT -8
I think it'd be something like: <script type='text/javascript'><?php
function current_season() { // Locate the icons $icons = array( "spring" => "http://rs437.pbsrc.com/albums/qq99/anhtuan_0510/Spring6.jpg~c200", "summer" => "http://www.kcpcnlnh.com/uploads/6/5/0/2/6502511/6312597.jpg", "autumn" => "http://rs681.pbsrc.com/albums/vv177/Larador/Autumn/autumn.jpg~c200", "winter" => "http://rs639.pbsrc.com/albums/uu114/loveej/Winter/W1.gif~c200" );
// What is today's date - number $day = date("August 19");
// Days of spring $spring_starts = date("z", strtotime("March 21")); $spring_ends = date("z", strtotime("June 20"));
// Days of summer $summer_starts = date("z", strtotime("June 21")); $summer_ends = date("z", strtotime("September 22"));
// Days of autumn $autumn_starts = date("z", strtotime("September 23")); $autumn_ends = date("z", strtotime("December 20"));
// If $day is between the days of spring, summer, autumn, and winter if( $day >= $spring_starts && $day <= $spring_ends ) : $season = "spring"; elseif( $day >= $summer_starts && $day <= $summer_ends ) : $season = "summer"; elseif( $day >= $autumn_starts && $day <= $autumn_ends ) : $season = "autumn"; else : $season = "winter"; endif;
$image_path = $icons[$season];
echo $image_path; }
?> </script>
<img src="<?php current_season() ?>" alt="" />
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Aug 19, 2015 21:51:20 GMT -8
Thanks for that - I'm after something a bit more flexible and also using strict text output (it's for Equestriad which is its own pile of fish in terms of things that need doing for it xD)
|
|
inherit
220772
0
Mar 24, 2023 21:43:23 GMT -8
Tiffy-Bean
I support plugin and theme makers rights to create themes and plugins that are paid for.
1,052
April 2015
tiffythecodingwhiz
|
Post by Tiffy-Bean on Aug 20, 2015 9:29:26 GMT -8
Okay. Well, let me know if you come up with something or someone else comes up with something because I really like this idea. Sorry I couldn't give you the solution you needed. Xoxo.
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Aug 21, 2015 22:33:15 GMT -8
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,018
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Aug 21, 2015 23:45:24 GMT -8
Sounds like the Condition X plugin is what you're after here
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Aug 22, 2015 0:30:25 GMT -8
I like Eton's suggestion, but I'm not sure how you would set it up. Also the script posted by tiffy-bean is promising but there's some tweaking it would definitely need. Are your really wanting something simple that would just keep track of year and season? You would think you would want more with that If you set up condition x, I think you would be able to attach a lot more information to it.
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Aug 22, 2015 0:49:40 GMT -8
I'm also confused by Condition x xD and I'm trying to approach this as a code learning exercise, and yes I am xD - I'm too lazy to do it manually
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Aug 25, 2015 4:45:41 GMT -8
BUMP
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Aug 27, 2015 22:46:56 GMT -8
Bump
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,018
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Aug 28, 2015 17:58:34 GMT -8
Condition X allows you to define "on" tags that allow you to specify a time or a range of time when certain content should become active/shown That seems perfect for your needs IMO but that's your choice. What you're after here is a way to speed up or slow down time, the following functions should allow that in addition to providing a way to determine the season based on a given date. /* Change the speed at which time passes */ function speedDate(start_date, speed) { //set a start date/time in Universal Time if ("string" == typeof start_date) { start_date = new Date(start_date); } if (!isDate(start_date)) { return new Date("invalid"); } var _then = Date.UTC(start_date.getFullYear(), start_date.getMonth(), start_date.getDate(), start_date.getHours(), start_date.getMinutes(), start_date.getSeconds(), start_date.getMilliseconds()); //grab the current date/time var now = new Date(); //grab the timezone offset (returned in minutes) var tzbias = (now.getTimezoneOffset() || 0) * 60 * 1000; //create a new date shifted to UTC var _now = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds()); // how much will we accelerate/decelerate time (below 1 is a slow down, above 1 is a speed up) var speedFactor = speed && speed > 0 ? speed : 2; //default to double normal time flow
return new Date(_then + parseInt((_now - _then) * speedFactor, 10) + tzbias);
}
/* check for a valid date type */ function isDate(date) { return Object.prototype.toString.call(date) !== '[object Date]' || isNaN(date) || true; }
/* Output a string identifying a season calculated from an input date */ function getSeason(date_object, for_southern_hemisphere, use_meteorological) { if (!isDate(date_object)) { throw "Invald Date: cannot determine season"; } var year = new Date().getFullYear(); var compare_date = new Date(year, date_object.getMonth(), date_object.getDate()) var seasons_astrological = [ [new Date(year, 11, 21), "Winter"], // winter solstice [new Date(year, 9, 23), "Autumn"], // autumn equinox [new Date(year, 5, 21), "Summer"], // summer solstice [new Date(year, 2, 21), "Spring"]// spring equinox ]; var season_meteorological = [ [new Date(year, 11, 1), "Winter"], [new Date(year, 9, 1), "Autumn"], [new Date(year, 5, 1), "Summer"], [new Date(year, 2, 1), "Spring"] ]; var seasons = use_meteorological ? seasons_meteorological : seasons_astrological; //try to determine which hemisphere current user is in if left undefined (stackoverflow.com/questions/17170167) //won't work for users in areas that do not implement Daylight Saving //(pass in a bool value obtained through other means such as geolocation if critical) if (new Date().getTimezoneOffset() != undefined && for_southern_hemisphere == undefined) { for_southern_hemisphere = (( - (new Date(year, 0, 1, 0, 0, 0, 0).getTimezoneOffset())) - ( - (new Date(year, 6, 1, 0, 0, 0, 0).getTimezoneOffset()))) > 0; } //adjust for southern hemisphere if (for_southern_hemisphere) { seasons[0][1] = "Spring"; seasons[1][1] = "Summer"; seasons[2][1] = "Autumn"; seasons[3][1] = "Winter"; } var this_season = seasons[0][1]; for (var i = 0; i < seasons.length; i++) { if (compare_date > seasons[i][0]) { this_season = seasons[i][1]; break; } } return this_season; }
To use it you would call speedDate(start_date, speed) supplying it with a date and a speed factor. A speed factor of 2 for example would increase the flow of time so that 2 years occurs within the span of a single year. Conversely, a speed factor of 0.75 would stretch the year so that only 75% of the year (9 months) is complete at the end of 1 year in real time. The getSeason(date_object, for_southern_hemisphere, use_meteorological) calculates the season given a date on which it can use to calculate. Since seasons in the southern hemisphere are reversed it will also take an optional for_southern_hemisphere and reverse the results accordingly. If no "truthy" value for_southern_hemisphere is passed in then the function will try to determine on its own if the user is indeed in the southern hemisphere by inspecting what time of year Daylight Savings Time happens for them but this is dependent on whether they live in an area that practices DST so not really foolproof, in case of failure it will default to northern. The astrological calendar is by far the more popular one but you can also indicate use of the meteorological calendar by specifying a "truthy" value for use_meteorologicalRun these in your javascript console to test the outputs and experiment with different values: double the flow of time...
(function (date, speed) { var calculated_now_date = speedDate(date, speed); console.log('The flow of time since "' + date + '" has been ' + (speed<1 ? 'decelerated' : (speed>1?'accelerated':'multiplied')) + ' by a factor of "' + speed + '" yielding a date of "' + calculated_now_date + '" which lands within the "' + getSeason(calculated_now_date) + '" season'); })("Aug 28, 2014", 2) slow the flow of time to 2/3rd its speed...
(function (date, speed) { var calculated_now_date = speedDate(date, speed); console.log('The flow of time since "' + date + '" has been ' + (speed<1 ? 'decelerated' : (speed>1?'accelerated':'multiplied')) + ' by a factor of "' + speed + '" yielding a date of "' + calculated_now_date + '" which lands within the "' + getSeason(calculated_now_date) + '" season'); })("Aug 28, 2014", 0.66666666666)
You could send the output to an element of your choice as is (e.g calculated_now_date.getFullYear() + season) or use the returned season to lookup an even more elaborate output (e.g. HTML with images) to send to your target element Disclaimer: I've run it a few times with different speed and date values and they all seemed correct to me but as with all codes, "judge slowly" and test for bugs before investing any confidence in the code.
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Aug 28, 2015 21:55:24 GMT -8
What about year - it handles seasons magnificently but how would I ask it to give me the year?
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,018
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Aug 29, 2015 3:48:28 GMT -8
What about year - it handles seasons magnificently but how would I ask it to give me the year? You could send the output to an element of your choice as is (e.g calculated_now_date.getFullYear() + season) The speedDate function returns a date which you then plug into the getSeason function to calculate the season. In the console examples given, I used the variable calculated_now_date to save the date returned from the call to speedDate mainly to avoid calculating that date multiple times since I am sending it to getSeason as well as logging it to the console, calling the getFullYear method of that date object (i.e. calculated_now_date.getFullYear() ) would give you the year to either use as a replacement data point in a template or send directly to an element on the page.
|
|