In the last video we got our latitude down into our season display component.
Now the only other thing we have to do is figure out the current month and then use the latitude and
the month to decide if it is summer or winter and getting the month is actually going to be pretty straightforward.
If you open up a javascript console really quickly you can do new dates that get month like so that's
going to return an integer indicating the current month of the year.
Note that this is a zero index date.
So 10 indicate the eleventh month of the year.
So for me right now I'm recording this in November of 10 would be mean November to put numbers gee all
these different months this is what you would get.
So we start off with zero month as being January 1 is fed and over year 10 like I said would be in November.
Now we're going to kind of simplify our season determination here.
We're going to say that if we are between April and September then it's going to be summer indicated
by these orange boxes for the Northern Hemisphere.
But if our users in the southern hemisphere and it is between January February March or October November
December then we're going to say that it's summer for them down there.
All right so now that we have these rules in mind let's flip back over to our editor and we're going
to put together a little bit of code to essentially determine the current season as a string.
So I want to end up with a simple string that says Summer or Winter.
I'm going to define a new function above my component's season display whose sole purpose is to determine
what the season is.
Now I could definitely put the code for this inside the body of season display but personally I like
to extract as much logic out as functional components as possible.
So if you're going to say get season and this is going to be a function that we'll call with the current
latitude and the current month.
And before we put any logic aside there let's make sure that we will be able to call that function from
inside side of the season display component.
I will remove the console log and then I will say conc season will be a good season.
I'll pass in my latitude which is stored on Propst not lat.
I meant to get the month we'll do a new date.
Don't get much like the.
So now our Get season function is going to get the current latitude and the month now we can write a
little bit of logic in here to return either the string summer or the spring summer winter Scarne.
Sorry I'm reading summer in winter on my screen right now as I say those words.
I get so inside of your There's a ton of different ways we could write this logic.
I've got one way of writing the logic that's nearly compact and somewhat easy to read so I'm going to
say if a month is greater than 2 and the month is less than 9 so that would indicate that we are in
this group of months right here.
So then we will determine whether or not we are in a northern hemisphere location in which case would
be summer or we are in Southern.
In which case it would be winter.
So to do so we're going to use a javascript ternary expression will do so by saying.
Latt is flat greater than zero if it is that means that we must be in the northern hemisphere.
I'll then put in a question mark.
If we are in the northern hemisphere then I want to return the values summer.
Otherwise I want to return the value winter like so.
So again the say javascript ternary expression this expression right here will be evaluated if it returns
True.
Then we're going to return summer from the overall expression.
Otherwise if Lat is less than zero then we will return winter instead.
The logic here is somewhat straightforward if we are in the summer months and we are in the northern
hemisphere return summer otherwise return winter and I'm going to make sure I put on a return statement
like so now we're going to return the result of this entire ternary expression.
Now this right here is only going to handle the summer months so I'm going to put in an L-Space and
it will put in basically the same Turner expression here.
So this would now be the case in which we are in the months.
January February March or October November December.
So once again we need to determine if we are in the northern hemisphere or Southern Hemisphere and then
return the appropriate string.
So I will return lat less than zero at this time.
We're going to reverse the order of months.
So now if we are in the northern hemisphere during the winter months that must mean we are in winter.
Otherwise we must be in the southern hemisphere in which case we are in summer all right.
Like I said many different ways to write out this expression right here.
This is just one way that seems somewhat reasonable and somewhat easy to put together.
So now to make sure that that is working correctly I'm going to put a console log for season down inside
my component and then I will refresh my application and make sure that the correct season is being displayed.
So I currently have winter which for me is actually correct.
It is winter here because I'm in the northern hemisphere and it is the winter months to test this out
very easily.
I could change my hardcoded geo location or the location overnight down here so I will say that I am
in Sao Paolo which is in the southern hemisphere and so now if I refresh I should see summer and in
fact I do.
All right so it looks pretty good.
So we now have our season.
The last thing we have to do is do a little bit of styling inside of our season display component so
quick pause and we'll start to take care of that in the next video.