VB.net does not seem to have adequate structure for handling time
within it's own code.
Subtract 15 minutes from 00:00 AM, and an out of range condition results.
Subtract 15 minutes from 12:00 PM, and the result is 11:45 AM,
as it should be.
Seems one half of the process is missing, and it is the half that requires
the most thought. Without it, we are left to hand code the whole process.
Time has a standard, and it should be properly implemented in the language.
Time is also one of the most commonly used routines in programming.
While I could work around the VB time construct programmaticall y, I feel
that the issue should be addressed. At least it should work with local time,
with only UTC conversion requiring additional code.
Why is it the way it is?
Here's the code:
Private Sub btnAction_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnAction.Click
'begin StartText
Dim StartText As String = txbStart.Text
Dim HourParse As String = Mid(StartText, 1, 2)
Dim HourDbl As Double = Val(HourParse)
Dim HourInt As Integer = CInt(HourDbl)
Dim MinParse As String = Mid(StartText, 4, 2)
Dim MinDbl As Double = Val(MinParse)
Dim MinInt As Integer = CInt(MinDbl)
Dim SecInt As Integer = 0
Dim FunctionTime As Date = TimeSerial(Hour Int, MinInt, SecInt)
Dim StartLabelText As String = Format(Function Time, "hh:mm tt")
'Set Start Time Label
lblStartUpR.Tex t = StartLabelText
'end StartText
'begin PreStart
Dim PreStart As String = txbPreStart.Tex t
HourParse = Mid(PreStart, 1, 2)
HourDbl = Val(HourParse)
HourInt = CInt(HourDbl)
MinParse = Mid(PreStart, 4, 2)
MinDbl = Val(MinParse)
MinInt = CInt(MinDbl)
'Begin Calc
Dim MinusHour As Double = HourDbl * -1
Dim MinusMin As Double = MinDbl * -1
Dim PreStartHour As Date = DateAdd(DateInt erval.Hour, MinusHour,
CDate(txbStart. Text))
Dim PreStartHourDbl As Double = Val(PreStartHou r)
Dim PreStartHourInt As Integer = CInt(PreStartHo urDbl)
Dim PreStartMin As Date = DateAdd(DateInt erval.Minute, MinusMin,
CDate(txbStart. Text))
Dim PreStartMinDbl As Double = Val(PreStartMin )
Dim PreStartInt As Integer = CInt(PreStartMi nDbl)
FunctionTime = TimeSerial(Hour Int, MinInt, SecInt)
StartLabelText = Format(Function Time, "hh:mm tt")
lblArrivalR.Tex t = PreStartMin.ToS hortTimeString
End Sub
txbStart is a textbox. The time is entered in 24hour format as hh:mm.
lblStartUpR is a label that displays the time in short time format
txbPreStart is a textbox taking the same format.
lblArrivalR is a label that displays the time in short time format that is a
result of the following calculation:
txbPreStart is subtracted (by addition of a minus value) from txbStart
'Should I write simpler and tighter code to throw the exception? 11 2275
"Dennis D." <te**@dennisys. com> schrieb VB.net does not seem to have adequate structure for handling time within it's own code. Subtract 15 minutes from 00:00 AM, and an out of range condition results. Subtract 15 minutes from 12:00 PM, and the result is 11:45 AM, as it should be. Seems one half of the process is missing, and it is the half that requires the most thought. Without it, we are left to hand code the whole process. Time has a standard, and it should be properly implemented in the language. Time is also one of the most commonly used routines in programming. While I could work around the VB time construct programmaticall y, I feel that the issue should be addressed. At least it should work with local time, with only UTC conversion requiring additional code.
Why is it the way it is?
You must distinguish between a certain point in time and a Timespan. The
first is expressed by a Date (DateTime) value and the second by a Timespan
(System.TimeSpa n) value. The time within a day is also expressed by a
Timespan (the timespan since midnight) as you see by having a look at the
data type of DateTime.TimeOf Day.
A certain point in time is composed of a date and a time. The smallest value
is DateTime.MinVal ue (01/01/0001 00:00) and the largest ist
DateTime.MaxVal ue.
So, your fault is to use a DateTime variable to store the time of the day.
When you use
PreStartHour As Date = DateAdd(DateInt erval.Hour, MinusHour,
CDate(txbStart. Text))
then you are trying to subtract 1 hour from 01/01/0001 00:00. This is not
possible because this date is already the smallest value possible for a
DateTime structure.
I don't understand the purpose of your procedure, but I suggest to use the
members of the DateTime and TimeSpan structures to convert from/to
String/DateTime/Timespan, like
- DateTime.Parse, DateTime.ParseE xact
- DateTime.Add, DateTime.Subtra ct
- Constructors for DateTime and TimeSpan
- TimeSpan.Add
and all the other members.
Maybe you could describe the purpose of the procedure and I can show you how
I would implement it.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
"Armin Zingler" <az*******@free net.de> wrote in message
news:40******** *************** @news.freenet.d e... "Dennis D." <te**@dennisys. com> schrieb VB.net does not seem to have adequate structure for handling time within it's own code. Subtract 15 minutes from 00:00 AM, and an out of range condition results. Subtract 15 minutes from 12:00 PM, and the result is 11:45 AM, as it should be. Seems one half of the process is missing, and it is the half that requires the most thought. Without it, we are left to hand code the whole process. Time has a standard, and it should be properly implemented in the language. Time is also one of the most commonly used routines in programming. While I could work around the VB time construct programmaticall y, I feel that the issue should be addressed. At least it should work with local time, with only UTC conversion requiring additional code.
Why is it the way it is? You must distinguish between a certain point in time and a Timespan. The first is expressed by a Date (DateTime) value and the second by a Timespan (System.TimeSpa n) value. The time within a day is also expressed by a Timespan (the timespan since midnight) as you see by having a look at the data type of DateTime.TimeOf Day.
A certain point in time is composed of a date and a time. The smallest
value is DateTime.MinVal ue (01/01/0001 00:00) and the largest ist DateTime.MaxVal ue.
So, your fault is to use a DateTime variable to store the time of the day. When you use
PreStartHour As Date = DateAdd(DateInt erval.Hour, MinusHour, CDate(txbStart. Text))
then you are trying to subtract 1 hour from 01/01/0001 00:00. This is not possible because this date is already the smallest value possible for a DateTime structure.
I don't understand the purpose of your procedure, but I suggest to use the members of the DateTime and TimeSpan structures to convert from/to String/DateTime/Timespan, like - DateTime.Parse, DateTime.ParseE xact - DateTime.Add, DateTime.Subtra ct - Constructors for DateTime and TimeSpan - TimeSpan.Add and all the other members.
Maybe you could describe the purpose of the procedure and I can show you
how I would implement it. -- Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
That's my point exactly.
A date is assumed, or you must give the program a date
(as January 01, 2001).
But when is not 00:00 minus 00:15 not 23:45 on a
24 hour clock? It is always 23:45!
So why go through all this code to arrive at a simple fact?
It should require 2 lines of code at worst to say:
00:00 - 00:15 == 23:45
Because at this point no one has assumed anything.
No one has said Daylight savings, or past the Prime Meridian.
If I wanted to specifiy something extra, such as DST or UTC,
then I could understand the difficulty of being required to
provide more information.
But a time type should have some simple unassuming
assumptions, that if you move past the negative boundry it
subtracts one unit from the parent, whatever that is.
0 - 1 = -1, how difficult is that?
In time: 00:00 - 00:15 = 23:45, or
00:00 - 01:01 = 23:59, seems simple enough to me.
That's not how it works?
I know.
That is why I am recommending action.
A high level language shouldn't have a problem with this.
oops: 00:00 - 01:01 = 22:59
I think. Brain Fart!
"Dennis D." <te**@dennisys. com> wrote in message
news:eY******** ******@TK2MSFTN GP12.phx.gbl... "Armin Zingler" <az*******@free net.de> wrote in message news:40******** *************** @news.freenet.d e... "Dennis D." <te**@dennisys. com> schrieb VB.net does not seem to have adequate structure for handling time within it's own code. Subtract 15 minutes from 00:00 AM, and an out of range condition results. Subtract 15 minutes from 12:00 PM, and the result is 11:45 AM, as it should be. Seems one half of the process is missing, and it is the half that requires the most thought. Without it, we are left to hand code the whole process. Time has a standard, and it should be properly implemented in the language. Time is also one of the most commonly used routines in programming. While I could work around the VB time construct programmaticall y, I feel that the issue should be addressed. At least it should work with local time, with only UTC conversion requiring additional code.
Why is it the way it is?
You must distinguish between a certain point in time and a Timespan. The first is expressed by a Date (DateTime) value and the second by a
Timespan (System.TimeSpa n) value. The time within a day is also expressed by a Timespan (the timespan since midnight) as you see by having a look at
the data type of DateTime.TimeOf Day.
A certain point in time is composed of a date and a time. The smallest value is DateTime.MinVal ue (01/01/0001 00:00) and the largest ist DateTime.MaxVal ue.
So, your fault is to use a DateTime variable to store the time of the
day. When you use
PreStartHour As Date = DateAdd(DateInt erval.Hour, MinusHour, CDate(txbStart. Text))
then you are trying to subtract 1 hour from 01/01/0001 00:00. This is
not possible because this date is already the smallest value possible for a DateTime structure.
I don't understand the purpose of your procedure, but I suggest to use
the members of the DateTime and TimeSpan structures to convert from/to String/DateTime/Timespan, like - DateTime.Parse, DateTime.ParseE xact - DateTime.Add, DateTime.Subtra ct - Constructors for DateTime and TimeSpan - TimeSpan.Add and all the other members.
Maybe you could describe the purpose of the procedure and I can show you how I would implement it. -- Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
That's my point exactly. A date is assumed, or you must give the program a date (as January 01, 2001). But when is not 00:00 minus 00:15 not 23:45 on a 24 hour clock? It is always 23:45! So why go through all this code to arrive at a simple fact? It should require 2 lines of code at worst to say: 00:00 - 00:15 == 23:45 Because at this point no one has assumed anything. No one has said Daylight savings, or past the Prime Meridian. If I wanted to specifiy something extra, such as DST or UTC, then I could understand the difficulty of being required to provide more information. But a time type should have some simple unassuming assumptions, that if you move past the negative boundry it subtracts one unit from the parent, whatever that is. 0 - 1 = -1, how difficult is that? In time: 00:00 - 00:15 = 23:45, or 00:00 - 01:01 = 23:59, seems simple enough to me. That's not how it works? I know. That is why I am recommending action. A high level language shouldn't have a problem with this.
"Dennis D." <te**@dennisys. com> schrieb
IMO your logical approach is not completely correct. You're saying that
00:00 - 01:01 = 22:59. That's only 1/2 truth. The whole truth is that it is
"22:59 the day before". This can be expressed by a Timespan:
dim ts as new timespan
ts = ts.subtract(new timespan(1, 1, 0)) '00:00
msgbox ts.tostring '=> -01:01:00
What would happen if you subtract 25 hours and 1 minute? Your result would
*also* be 22:59. So, subtracting 1 hour or subtracting 25 hours would lead
to the *same* result? I don't think it is correct because you are ignoring
the day. Do you really want to ignore the day? I'm almost sure you can't
because there will probably any calculation using the result of the
subtraction. Won't it? What are you going to do with the result of the
subtraction?
--
Armin oops: 00:00 - 01:01 = 22:59 I think. Brain Fart!
"Dennis D." <te**@dennisys. com> wrote in message news:eY******** ******@TK2MSFTN GP12.phx.gbl... "Armin Zingler" <az*******@free net.de> wrote in message news:40******** *************** @news.freenet.d e... "Dennis D." <te**@dennisys. com> schrieb > VB.net does not seem to have adequate structure for handling > time > within it's own code. > Subtract 15 minutes from 00:00 AM, and an out of range > condition results. Subtract 15 minutes from 12:00 PM, and the > result is 11:45 AM, > as it should be. > Seems one half of the process is missing, and it is the half > that requires the most thought. Without it, we are left to hand > code the whole process. Time has a standard, and it should be > properly implemented in the language. Time is also one of the > most commonly used routines in programming. While I could work > around the VB time construct programmaticall y, I feel that the > issue should be addressed. At least it should work with local > time, with only UTC conversion requiring additional code. > > Why is it the way it is?
You must distinguish between a certain point in time and a Timespan. The first is expressed by a Date (DateTime) value and the second by a Timespan (System.TimeSpa n) value. The time within a day is also expressed by a Timespan (the timespan since midnight) as you see by having a look at the data type of DateTime.TimeOf Day.
A certain point in time is composed of a date and a time. The smallest value is DateTime.MinVal ue (01/01/0001 00:00) and the largest ist DateTime.MaxVal ue.
So, your fault is to use a DateTime variable to store the time of the day. When you use
PreStartHour As Date = DateAdd(DateInt erval.Hour, MinusHour, CDate(txbStart. Text))
then you are trying to subtract 1 hour from 01/01/0001 00:00. This is not possible because this date is already the smallest value possible for a DateTime structure.
I don't understand the purpose of your procedure, but I suggest to use the members of the DateTime and TimeSpan structures to convert from/to String/DateTime/Timespan, like - DateTime.Parse, DateTime.ParseE xact - DateTime.Add, DateTime.Subtra ct - Constructors for DateTime and TimeSpan - TimeSpan.Add and all the other members.
Maybe you could describe the purpose of the procedure and I can show you how I would implement it. -- Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
That's my point exactly. A date is assumed, or you must give the program a date (as January 01, 2001). But when is not 00:00 minus 00:15 not 23:45 on a 24 hour clock? It is always 23:45! So why go through all this code to arrive at a simple fact? It should require 2 lines of code at worst to say: 00:00 - 00:15 == 23:45 Because at this point no one has assumed anything. No one has said Daylight savings, or past the Prime Meridian. If I wanted to specifiy something extra, such as DST or UTC, then I could understand the difficulty of being required to provide more information. But a time type should have some simple unassuming assumptions, that if you move past the negative boundry it subtracts one unit from the parent, whatever that is. 0 - 1 = -1, how difficult is that? In time: 00:00 - 00:15 = 23:45, or 00:00 - 01:01 = 23:59, seems simple enough to me. That's not how it works? I know. That is why I am recommending action. A high level language shouldn't have a problem with this.
Hi Armin,
First time I see you in this newsgroup.
Did you see that Dennis told he saw it wrong?
Cor
"Cor Ligthert" <no**********@p lanet.nl> schrieb Hi Armin,
First time I see you in this newsgroup.
Did you see that Dennis told he saw it wrong?
No, Cor. I read his post now again, but I dont' see it. What do you mean?
--
Armin
Hi Armin,
By Dennis as answer on his own message which was an answer to you. oops: 00:00 - 01:01 = 22:59 I think. Brain Fart!
Although your message is of course a good addition.
Cor
"Armin Zingler" <az*******@free net.de> wrote in message
news:40******** *************** @news.freenet.d e... "Dennis D." <te**@dennisys. com> schrieb
What are you going to do with the result of the subtraction?
Ever notice that most clocks do not have day or date features?
So why should an object oriented programming language that types a time
function ignore that fact, and require a date?
Hi Dennis,
Exacly here you show the superiority of human on a computer. Ever notice that most clocks do not have day or date features? So why should an object oriented programming language that types a time function ignore that fact, and require a date?
We do not have to know that, millions years of evolution have learned us the
changing of the day.
However the clock is not such a natural thing and now we need a clock for
that to try to get those times.
Here a link for that http://www.ernie.cummings.net/clock.htm
Just my thought,
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Scott Marquardt |
last post by:
Consider a table that holds Internet browsing history for users/machines,
date/timed to the minute. The object is to tag all times that are separated
by previous and subsequent times by x number of minutes or less (it could
vary, and wouldn't necessarily be a convenient round number). This will
enable reporting "active time" for users (a dubious inference, but hey).
There are a lot of derivative ways of seeing this information that might...
|
by: P. Ter Horst |
last post by:
The company I work for runs applications in batch. At midnight we have
a deadline for a certain application. The End-Time of that application
is exported to Access.
The data in the table looks something like this:
DATE: END-TIME:
04-05-2003 23:12
05-05-2003 00:14
06-05-2003 23:45
|
by: bonehead |
last post by:
Greetings,
A friend tells me that he has not been able to work out an expression
that calculates elapsed minutes from TimeA to TimeB.
For example:
TIMEA TIMEB ELAPASED
----- ----- --------
11:30AM 12:35PM 65
|
by: GGerard |
last post by:
Using Access2000
I have an application that is running 24/7 and I would like this application
to perform some routine housekeeping task at midnight.
What would be an efficient way of doing this; of detecting when midnight
|
by: Jozef Jarosciak |
last post by:
I need the function to tell me how many minutes past so far this month.
| |
by: Dennis D. |
last post by:
VB.net does not seem to have adequate structure for handling time
within it's own code.
Subtract 15 minutes from 00:00 AM, and an out of range condition results.
Subtract 15 minutes from 12:00 PM, and the result is 11:45 AM,
as it should be.
Seems one half of the process is missing, and it is the half that requires
the most thought. Without it, we are left to hand code the whole process.
Time has a standard, and it should be properly...
|
by: Lad |
last post by:
Hello,
what is the best /easest way how to get number of hours and minutes
from a timedelta object?
Let's say we have
aa=datetime.datetime(2006, 7, 29, 16, 13, 56, 609000)
bb=datetime.datetime(2006, 8, 3, 17, 59, 36, 46000)
so
c=bb-aa
will be
datetime.timedelta(5, 6339, 437000)
|
by: onedbguru |
last post by:
DB2Connect Informational tokens are "DB2 v8.1.0.96", "s050811",
"U803921", FixPak "10".
I am getting txxxxxx.0000 files approximately every 14 minutes that
look like:
<Trap>
<Header>
DB2 build information: DB2 v8.1.0.96 s050811 SQL08023
timestamp: 2007-02-15-01.37.12.101223
instance name: db2inst1.000
|
by: jld730 |
last post by:
Hello All,
I am very new to Python and Oracle, and I have a question for you all. How do you add/subtract minutes to a date? Is this possible? I need to add/subtract 30 minutes (or 60, or 90, etc) to/from a user-defined date-and-time, and then select based on that date-and-time-range. So, if I have a date looking like '2002-03-14 17:42:00', 'YYYY-MM-DD HH24:MI:SS', is there a way to add 30 minutes to it to get the right-side of the time...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |