1
00:00:01,140 --> 00:00:07,260
Welcome back and this video, we are going to finalize our calculation and we will finally display the

2
00:00:07,270 --> 00:00:15,720
age in minutes and therefore we're going to use this date object that we created and we will, first

3
00:00:15,720 --> 00:00:18,140
of all, get the date in minutes.

4
00:00:18,150 --> 00:00:29,090
So follow selected date in minutes and that will be the date that time.

5
00:00:29,970 --> 00:00:32,880
So I want to have the time of my date.

6
00:00:33,480 --> 00:00:40,050
Now, you can see that time is in purple and you can press the control key and hover over it and then

7
00:00:40,050 --> 00:00:40,740
press on it.

8
00:00:40,740 --> 00:00:47,100
And it will open up the data Java file, which contains this get method, which is called get time,

9
00:00:47,460 --> 00:00:55,710
which then returns to get time implemented, which then looks at if the date is not normalized or not

10
00:00:55,710 --> 00:01:01,060
null, then it will normalize it and return first time.

11
00:01:01,110 --> 00:01:02,370
What does all of that mean?

12
00:01:02,610 --> 00:01:04,989
Well, it will return it in a certain format.

13
00:01:05,310 --> 00:01:07,440
I will return it in.

14
00:01:08,810 --> 00:01:14,420
Milliseconds, so if you want to get seconds from milliseconds, we divide by one thousand.

15
00:01:14,810 --> 00:01:18,400
If you want to get minutes, then we divide by sixty thousand.

16
00:01:18,620 --> 00:01:24,800
When we do so and we have our overall date, the date we can see that it says unsafe use of nullable

17
00:01:24,800 --> 00:01:31,840
receiver of type date, which means that the date could be null and could be empty.

18
00:01:32,330 --> 00:01:38,480
And if that's the case and we still want to use it, we can force on Reppert, we can say, OK, the

19
00:01:38,480 --> 00:01:41,960
date is going to be a date object and it's going to work.

20
00:01:42,110 --> 00:01:44,180
So please go ahead and accept it.

21
00:01:44,660 --> 00:01:48,470
And we can do so by using the double exclamation mark here.

22
00:01:50,680 --> 00:01:55,130
This is, of course, tricky if the date is, in fact, not correct.

23
00:01:55,150 --> 00:02:03,080
So if the date is in fact empty or parsing the selected date that we selected doesn't work and so forth.

24
00:02:03,280 --> 00:02:10,110
So, for example, if we made an error when entering this value here, we have to be, of course, super

25
00:02:10,120 --> 00:02:10,600
careful.

26
00:02:11,020 --> 00:02:16,000
So this is something that you should only do if you are certain that the values that you have there

27
00:02:16,150 --> 00:02:16,780
are correct.

28
00:02:16,780 --> 00:02:23,860
Otherwise, you can, of course, build a whole try and catch block around it to check if everything

29
00:02:24,070 --> 00:02:27,510
is fine and and only execute it in a safe environment.

30
00:02:27,640 --> 00:02:29,250
But we're going to keep it simple for now.

31
00:02:29,290 --> 00:02:32,470
We could just say, OK, we force unwrap it.

32
00:02:32,470 --> 00:02:38,620
We say, OK, the date is having a value and we want to get the time from it.

33
00:02:38,980 --> 00:02:45,580
And then we want to divide that by 60 thousand in order to not get the milliseconds, but the actual

34
00:02:45,580 --> 00:02:54,760
minutes which have passed from the moment nineteen seventy 1st of January to the moment of our date.

35
00:02:56,580 --> 00:03:03,210
Because if you again, look at the documentation when we use that time, the gate time method is called

36
00:03:03,420 --> 00:03:10,260
and it returns the number of milliseconds since January 1st, nineteen seventy represented by this date

37
00:03:10,260 --> 00:03:10,860
object.

38
00:03:10,890 --> 00:03:13,830
OK, so that's what I was just talking about.

39
00:03:14,070 --> 00:03:14,450
All right.

40
00:03:14,460 --> 00:03:23,940
So this time, as we saw earlier, calls this get time method, which then in turn returns the time

41
00:03:23,940 --> 00:03:32,400
in milliseconds from 1970 to the moment of the state object, which is in my case, the 12th of December

42
00:03:32,550 --> 00:03:35,400
or actually the 11th of December, two thousand nineteen.

43
00:03:36,890 --> 00:03:42,920
So now that we know how much time has passed between the moment that was selected and 1970, we can

44
00:03:42,920 --> 00:03:50,300
also calculate how much time has passed between now the current day and the first of January, two thousand

45
00:03:51,020 --> 00:03:52,130
or nineteen seventy.

46
00:03:52,500 --> 00:03:56,390
OK, so we can go ahead and get the current date.

47
00:03:56,630 --> 00:04:01,820
Vul current date is equal to ASDF topass.

48
00:04:03,140 --> 00:04:06,260
And now we need to formate.

49
00:04:08,190 --> 00:04:09,900
System not.

50
00:04:11,370 --> 00:04:13,920
Current time in millisecond.

51
00:04:15,400 --> 00:04:21,370
So what I did here is I summed it up in one line, so here we did it before, we did it in multiple

52
00:04:21,370 --> 00:04:21,680
lines.

53
00:04:21,680 --> 00:04:31,840
So first we did get it in a certain format and then it was transferred into the right format, which

54
00:04:31,840 --> 00:04:34,810
then was in turn transformed or.

55
00:04:38,250 --> 00:04:40,230
Converted into a date object.

56
00:04:41,070 --> 00:04:48,060
All right, so here we bring it into the right format, then we bring it into the date object type or

57
00:04:48,060 --> 00:04:54,660
into the date type, and we start in current date and now we can go ahead and calculate the current.

58
00:04:56,060 --> 00:05:00,050
That two minutes, which is going to be the current date.

59
00:05:01,150 --> 00:05:05,940
Which if you look at it here, by the way, current date, it says date questionmark, which means that

60
00:05:05,950 --> 00:05:09,210
current date is an optional or a null type.

61
00:05:10,120 --> 00:05:11,350
So current date.

62
00:05:12,950 --> 00:05:18,890
Here we need to double exclamation mark again, but time divided by sixty thousand.

63
00:05:21,180 --> 00:05:24,510
And now we can go ahead and calculate the difference, so.

64
00:05:25,810 --> 00:05:27,160
Voll Differenced.

65
00:05:28,240 --> 00:05:34,660
In minutes, this current dates to minutes minus selected.

66
00:05:35,900 --> 00:05:44,680
Date in minutes and actually let's keep the same naming, I'm going to use that in minutes here, so

67
00:05:44,700 --> 00:05:45,950
like to take ten minutes.

68
00:05:47,030 --> 00:05:48,270
And yeah, that's it.

69
00:05:48,560 --> 00:05:56,930
So now we have the difference in minutes, which means we now have the value that in fact is the H in

70
00:05:56,930 --> 00:06:01,510
minutes so we can use selected data in minutes.

71
00:06:01,520 --> 00:06:06,740
Our TV, our text you, which is this text you here at the bottom.

72
00:06:08,100 --> 00:06:11,860
So let me scroll the way down here.

73
00:06:11,940 --> 00:06:17,340
This one TV selected data in minutes, which is just text you that is bigger with thirty five USPI,

74
00:06:17,640 --> 00:06:19,260
but which currently is empty.

75
00:06:19,920 --> 00:06:26,250
Now we can go ahead and set its text to our difference in minutes.

76
00:06:28,150 --> 00:06:33,790
And of course, this has to be a string, so to string just to make sure that it has the right format.

77
00:06:37,470 --> 00:06:41,730
All right, and now you can go ahead and test this, let's just see.

78
00:06:45,590 --> 00:06:48,530
All right, so let's select to date, let's say.

79
00:06:49,580 --> 00:06:52,520
We select the 10th of December.

80
00:06:54,030 --> 00:07:01,110
And the H in minutes is one thousand four hundred forty, which is one day, so one day is fourteen

81
00:07:01,110 --> 00:07:02,310
hundred and forty minutes.

82
00:07:02,730 --> 00:07:12,120
So let's say I select my birth date here, which is the 31st of May, nineteen eighty eight.

83
00:07:12,930 --> 00:07:15,080
And I can see this is my H.

84
00:07:17,790 --> 00:07:18,900
All right, that's it.

85
00:07:18,930 --> 00:07:21,240
That's our application, as you can see, it works fine.

86
00:07:21,270 --> 00:07:27,270
Now, let's check what happens if I select the wrong date, for example, something in the future,

87
00:07:28,140 --> 00:07:29,570
then we get a negative value.

88
00:07:29,880 --> 00:07:33,630
So we are minus two thousand eight hundred eighty minutes old.

89
00:07:33,840 --> 00:07:35,970
That's something that you can, of course, use for.

90
00:07:37,030 --> 00:07:40,660
Countdown timer or something like that, but our app is really.

91
00:07:41,870 --> 00:07:48,080
Are to calculate the ten minutes, so doing something like that where we have negative values is not

92
00:07:48,080 --> 00:07:48,900
going to cut it.

93
00:07:48,920 --> 00:07:50,660
That's not the right way to do it.

94
00:07:50,690 --> 00:07:57,700
So what we can do is we can store this whole data, picture, dialogue and a variable.

95
00:07:58,130 --> 00:08:06,620
So I'm just going to say Volle DPD, which stands for data picker dialogue, and then instead of showing

96
00:08:06,620 --> 00:08:09,080
it directly here, I'm just going to.

97
00:08:11,000 --> 00:08:19,580
First of all, limit this DVD or set a setting there, so I'm just going to say DVD dot date picker.

98
00:08:20,640 --> 00:08:23,970
And here I can set the megastate.

99
00:08:26,420 --> 00:08:35,100
And it will be date time, minus eight, six, four and five zeros.

100
00:08:35,960 --> 00:08:38,330
This is just the milliseconds of one day.

101
00:08:39,620 --> 00:08:42,970
And in the next step, I will show the DPD.

102
00:08:43,549 --> 00:08:44,390
So our.

103
00:08:45,310 --> 00:08:47,830
Day to pick your dialogue now this test is again.

104
00:08:49,730 --> 00:08:55,280
So let's select a date in the future, and as you can see, I cannot do it so it doesn't even offer.

105
00:08:56,410 --> 00:09:03,160
These states, so it's limited to the past and I cannot use the future, and how is that possible?

106
00:09:03,520 --> 00:09:11,380
Well, it was made possible by setting the next date to the date, the time, which is the current time

107
00:09:11,800 --> 00:09:12,400
minus.

108
00:09:13,480 --> 00:09:19,840
One day, so we can only select yesterday as the latest moment.

109
00:09:21,290 --> 00:09:27,500
All right, so that's our little app, and I took a little longer than I expected, but that's because

110
00:09:27,500 --> 00:09:32,780
I really went deep into depth here and I really explained very many details.

111
00:09:33,140 --> 00:09:40,360
And yeah, you can, of course, always download the application or better said the project.

112
00:09:40,580 --> 00:09:46,520
And there you will find that we have many comments which explain what's going on there and why the code

113
00:09:46,520 --> 00:09:47,420
is as it is.

114
00:09:47,720 --> 00:09:49,400
So you can just download that.

115
00:09:49,400 --> 00:09:53,420
And that will definitely help you to understand what's going on if something is unclear.

116
00:09:53,990 --> 00:09:56,540
There might be some names which are a little different.

117
00:09:56,540 --> 00:10:01,580
Maybe I decided to change the names while I created the recording, but overall it's pretty much the

118
00:10:01,580 --> 00:10:02,140
same code.

119
00:10:02,360 --> 00:10:07,790
I hope to take advantage of this and of course, also of the documentation because it's super helpful

120
00:10:07,790 --> 00:10:09,110
to understand what's going on.

121
00:10:09,770 --> 00:10:10,220
All right.

122
00:10:10,220 --> 00:10:12,460
So I hope you enjoyed this chapter and.

123
00:10:12,740 --> 00:10:13,790
Yeah, see you in the next one.

