WEBVTT

00:00.730 --> 00:01.240
Hi everyone.

00:01.240 --> 00:02.530
Welcome back to this tutorial.

00:02.530 --> 00:07.720
In this tutorial, we'll explore some of the additional methods that Localdate supports.

00:07.720 --> 00:12.490
Before I get into that, I would like to explain one more scenario which I missed to explain in the

00:12.490 --> 00:13.660
previous tutorial.

00:14.020 --> 00:19.060
Now I want to attract the years by one.

00:19.240 --> 00:19.860
How do we do it?

00:19.870 --> 00:25.480
Normally we can use the minus years, but there is another approach which we can do if we want to subtract

00:25.480 --> 00:28.420
the years localdate dot minus years.

00:28.420 --> 00:33.460
If you provide the minus years value as one, it is going to subtract the year by one.

00:33.460 --> 00:39.730
But if you take a look at it, there is a there is another version of minus that is available here.

00:39.910 --> 00:44.920
We take a look at it minus long, the amount to subtract and then the temporal unit.

00:44.920 --> 00:45.970
Let's explore that.

00:45.970 --> 00:49.930
So in here, what we have to do is I want to subtract the year by one.

00:49.930 --> 00:52.870
And what is other attribute that it accepts?

00:52.870 --> 00:54.580
It accepts a temporal unit.

00:54.610 --> 00:58.930
The temporal unit is an interface that is part of the Java dot time package.

00:58.930 --> 00:59.980
And then.

01:02.270 --> 01:06.830
There is something called Chrono Unit which actually implements a temporal unit.

01:08.160 --> 01:11.850
The Chrono Unit is an enum that implements a temporal unit.

01:11.940 --> 01:15.520
Let's see, what are the different attributes that it supports?

01:15.520 --> 01:19.520
If we take a look at it, it supports minutes, years, seconds, months and all those things.

01:19.530 --> 01:23.190
So our use case is we want to subtract the year by one, right?

01:23.190 --> 01:27.420
So in that case, we will pass this and let's give a comment.

01:28.660 --> 01:30.370
You know, unit minus.

01:34.290 --> 01:34.620
Okay.

01:34.830 --> 01:36.240
Let's go ahead and run this one.

01:38.420 --> 01:41.660
If we take a look at the Chrono unit, minus two is 2017.

01:41.660 --> 01:44.750
So we subtracted the year by one using this.

01:44.780 --> 01:48.560
Again, this is one another approach of subtracting the year.

01:48.590 --> 01:52.970
All these methods are really handy and each and every method, what are we covered?

01:52.970 --> 01:57.410
There is an alternative for each and every approach, but ultimately it is going to give you the same

01:57.410 --> 01:57.860
result.

01:58.070 --> 02:02.540
It's your comfort to choose what are options that you feel comfortable with.

02:02.720 --> 02:06.860
Now let's explore some of the additional support methods.

02:10.370 --> 02:10.940
Additional.

02:13.030 --> 02:13.540
A port.

02:15.290 --> 02:18.470
Let's say you want to check whether this year is a leap year or not.

02:20.050 --> 02:24.310
As a handy method available for that one to local date dot is leap year.

02:24.640 --> 02:30.580
This will tell you is 2017 not sorry, 2018 is a leap year or not.

02:32.940 --> 02:36.150
Here and 2018 is not a leap year.

02:36.150 --> 02:38.130
It's going to give you the result as false.

02:39.670 --> 02:40.000
Right.

02:40.000 --> 02:42.310
Let's see which year is leap year.

02:42.340 --> 02:43.640
2020 is a leap year.

02:43.660 --> 02:47.950
What I'm going to do, I'm going to do local date dot of.

02:48.970 --> 02:50.680
I'm going to create a date.

02:51.070 --> 03:01.600
Local date dot off and I'm going to pass the year as 2020 and the day as zero one.

03:02.520 --> 03:06.510
If you run this, this is going to give me the result as true here.

03:07.480 --> 03:11.020
And then I want to perform what is leap year, right?

03:11.020 --> 03:15.100
If you do not do that, it is not going to check whether it is a leap year or not.

03:16.520 --> 03:17.390
Run this.

03:18.390 --> 03:19.180
Take a look at the result.

03:19.200 --> 03:20.120
It is true.

03:20.130 --> 03:22.680
Previously the result came as false.

03:23.010 --> 03:26.940
Let's explore some more additional different methods.

03:28.600 --> 03:32.590
Let's say you want to check whether the two dates are equal or not.

03:32.630 --> 03:39.670
So here we have local date, which is a current date, and then the local date one, which is the date

03:39.670 --> 03:42.320
which is next to this day, which is 17.

03:42.340 --> 03:45.880
So the current date is actually 16.

03:47.030 --> 03:48.770
July 2018.

03:49.610 --> 03:51.980
Okay, now let's compare this.

03:53.480 --> 03:56.720
When I explore there is a method called is equal.

03:57.990 --> 03:58.520
Zequel.

03:58.520 --> 04:00.190
And then what is the input?

04:00.200 --> 04:03.560
It accepts a chronological date, which is nothing but the local date.

04:04.340 --> 04:05.690
The local date one.

04:06.790 --> 04:08.290
So local date.

04:08.320 --> 04:09.970
Let's put this comment here.

04:10.390 --> 04:14.140
Local date is 16th July.

04:15.680 --> 04:19.360
2018 and a local date one.

04:20.530 --> 04:22.210
This is 17th July.

04:27.720 --> 04:29.850
Chocolate one on 17th July.

04:32.610 --> 04:33.420
2018.

04:33.630 --> 04:35.010
If you run this.

04:35.860 --> 04:39.540
Put some comments here so that it will be easy to read from the console.

04:41.390 --> 04:46.190
Run this it's going to return false because is these dates are not equal.

04:46.340 --> 04:49.100
Local date represents 16th July local date.

04:49.130 --> 04:51.110
One represents 17th July.

04:51.380 --> 04:56.420
Now we will explore the another method which is is before is a local date.

04:56.420 --> 05:01.370
One before local date is local date before local date one.

05:01.370 --> 05:06.080
Yes, because local date is 16th of July and local date one is 17th of July.

05:06.290 --> 05:09.860
And now this is going to return the value as.

05:11.810 --> 05:14.390
If you take a look at the result, the result came as true.

05:14.420 --> 05:17.300
Now there is something called ease after.

05:19.580 --> 05:22.000
Now I'm going to change this instance a little bit.

05:22.010 --> 05:23.510
I'm going to have local date.

05:23.510 --> 05:27.320
One is before local date is after, right.

05:27.320 --> 05:27.800
Is after.

05:27.800 --> 05:30.500
The method that we're exploring is after local date one.

05:30.500 --> 05:35.180
So 17th, 17th of July is local date one, which is after the 16th of July.

05:35.180 --> 05:37.670
It is going to give us the result as.

05:40.280 --> 05:41.930
It gave you the result as true.

05:41.950 --> 05:46.010
These are the handy methods which you can use in order to compare two dates.

05:46.030 --> 05:50.770
There are a lot of different advanced methods which I'll be covering in the future tutorials, but for

05:50.770 --> 05:53.350
now this is one simple options.

05:53.380 --> 05:57.040
These are the options that we have in order to compare the dates.

05:57.040 --> 05:58.330
And these are intuitive.

05:58.360 --> 06:02.230
If you take a look at the method name, just by looking at the method name, you can say what is that

06:02.230 --> 06:05.080
functionality that it is going to perform.

06:05.530 --> 06:11.800
And now I'm going to give you some examples of not unsupported scenarios.

06:11.800 --> 06:13.240
Let's go ahead and explore that.

06:13.450 --> 06:16.060
I'm going to give something like unsupported.

06:18.060 --> 06:21.230
So here, this is completely local data, right?

06:21.240 --> 06:24.090
We are talking about date functionalities.

06:24.480 --> 06:28.710
Let's say you want to try to subtract a time from a date.

06:28.740 --> 06:29.640
What would happen?

06:29.910 --> 06:30.900
Let's explore that.

06:31.230 --> 06:37.590
I'm going to use this example here and then put it here in here what I'm going to do in the place of

06:37.590 --> 06:39.930
this, I'm going to give the value as.

06:41.030 --> 06:41.840
Minutes.

06:42.500 --> 06:44.630
Local date doesn't have a minutes at all.

06:44.630 --> 06:46.190
If you try to perform this.

06:46.220 --> 06:47.090
What would happen?

06:47.390 --> 06:49.670
Run this and check if you run this.

06:49.670 --> 06:52.160
Basically, this is going to give you something like.

06:52.190 --> 06:58.220
Unsupported temporal type exception unsupported unit minutes because you are working with date here,

06:58.220 --> 07:01.550
you cannot try to perform a date functionality.

07:01.580 --> 07:04.970
Time functionality on a date object.

07:05.120 --> 07:08.300
So this is something which you have to keep in your mind.

07:08.330 --> 07:10.310
There is something called is supported.

07:10.310 --> 07:14.840
That is something which you can use in order to check whether this particular operation is supported

07:14.840 --> 07:15.410
or not.

07:15.950 --> 07:19.760
I'm going to show you that is supported.

07:20.620 --> 07:25.690
What this is going to do is local date Dot is supported.

07:25.690 --> 07:32.830
So this is a method and then you can pass the unit, the Chrono unit dot units.

07:33.730 --> 07:39.070
Now, in our use case, this is going to print false because minutes is not supported.

07:39.610 --> 07:40.930
Go ahead and run this and check.

07:42.470 --> 07:45.450
Could he supported value came as false.

07:45.470 --> 07:49.580
If you give years, let's see what it is going to print.

07:52.020 --> 07:53.610
He supported us through so.

07:54.520 --> 08:01.240
Using this, you can find out whether can you perform that kind of operation on this object or not.

08:01.730 --> 08:05.080
So these are the different additional support methods that we have as part of local.

08:05.680 --> 08:09.340
You can actually use in your use cases.

08:09.700 --> 08:11.890
With this, we came to the end of this tutorial.

08:11.920 --> 08:13.000
Thank you for watching.
