How do I convert a length of time, measured in seconds, into a "point in
time" type time interval or what's represented as: time (second,10,2)
The format is:
P[yY][mM][dD][T[hH][mM][s[.s]S]] where:
y: The number of years (integer, >= 0, not restricted)
m: The number of months (integer, >=0, not restricted)
d: The number of days (integer, >=0, not restricted)
h: The number of hours (integer, >=0, not restricted)
n: The number of minutes (integer, >=0, not restricted)
s: The number of seconds or fraction of seconds (real or integer, >=0,
not restricted). If fractions of a second are used, SCORM further
restricts the string to a maximum of 2 digits (e.g., 34.45 – valid,
34.45454545 – not valid).
The character literals designators “P”,”Y”,”M”,”D” ,”T”,”H”,”M”,”S ” shall
appear if the corresponding non-zero value is present.
Example:
P1Y3M2DT3H indicates a period of time of 1 year, 3 months, 2 days and 3
hours
PT3H5M indicates a period of time of 3 hours and 5 minutes
It's used by the SCORM RTE to measure the length of session times.
I've had a few goes but the code starts to look like spaghetti then I
have to give up.
Andrew Poulos 4 2975
Andrew Poulos wrote: How do I convert a length of time, measured in seconds, into a "point in time" type time interval or what's represented as: time (second,10,2)
You may use the Date object from JavaScript. Create a new Date with your
given seconds (multiply with 1000 to get milliseconds):
var seconds = 200;
var date = new Date(seconds*10 00);
date.setFullYea r(0);
date.setMinutes (date.getMinute s()+date.getTim ezoneOffset());
Now you may use all the date methods to get the wanted values
getFullYear();
getMinutes();
getSeconds();
....
Daniel
Andrew Poulos <ap*****@hotmai l.com> writes: How do I convert a length of time, measured in seconds, into a "point in time" type time interval or what's represented as: time (second,10,2)
Representation not understood.
The format is:
P[yY][mM][dD][T[hH][mM][s[.s]S]] where:
y: The number of years (integer, >= 0, not restricted) m: The number of months (integer, >=0, not restricted) d: The number of days (integer, >=0, not restricted)
Here you have to make some definitions. Months doesn't all have the
same length, so how many seconds are a month? (there are six different
answers if you include daylight saving time changes).
Likewise, how long is a year? 365 or 366 days?
And depending on what it's used for, the varying length of a day might
also matter, when daylight saving changes.
It's used by the SCORM RTE to measure the length of session times.
No idea what SCORM RTE is either (ok, Google told me), but why not
just count the seconds. What else is needed?
I've had a few goes but the code starts to look like spaghetti then I have to give up.
Define what you need, then it's faily simple.
If you fix on 24 hours per day, 30 days per month and 12 months per year,
then:
---
function represent(time) {
var res = [];
var secs = time % 60;
if (secs) {
if (secs == Math.floor(secs )) {
res.push(secs + "S");
} else {
res.push(secs.t oFixed(2)+"M");
}
}
time = Math.floor(time / 60);
var mins = time % 60;
if (mins) {
res.push(mins + "M");
}
time = Math.floor(time / 60);
var hours = time % 24;
if (hours) {
res.push(hours + "H");
}
time = Math.floor(time / 24);
if (res.length) {
res.push("T");
}
var date = time % 30;
if (date) {
res.push(date + "D");
}
time = Math.floor(time / 30);
var months = time % 12;
if (months) {
res.push(months + "M");
}
time = Math.floor(time / 60);
if (time) {
res.push(time + "Y");
}
res.push("P");
return res.reverse().j oin("");
}
---
Good luck
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
JRS: In article <42aed83a$0$229 27$5a62ac22@per-qv1-newsreader-
01.iinet.net.au >, dated Tue, 14 Jun 2005 23:15:21, seen in
news:comp.lang. javascript, Andrew Poulos <ap*****@hotmai l.com> posted : How do I convert a length of time, measured in seconds, into a "point in time" type time interval or what's represented as: time (second,10,2)
What the latter might mean is unclear to me.
The format is:
P[yY][mM][dD][T[hH][mM][s[.s]S]] where:
y: The number of years (integer, >= 0, not restricted) m: The number of months (integer, >=0, not restricted) d: The number of days (integer, >=0, not restricted) h: The number of hours (integer, >=0, not restricted) n: The number of minutes (integer, >=0, not restricted) s: The number of seconds or fraction of seconds (real or integer, >=0, not restricted). If fractions of a second are used, SCORM further restricts the string to a maximum of 2 digits (e.g., 34.45 – valid, 34.45454545 – not valid). The character literals designators “P”,”Y”,”M”,”D” ,”T”,”H”,”M”,”S ” shall appear if the corresponding non-zero value is present.
Example: P1Y3M2DT3H indicates a period of time of 1 year, 3 months, 2 days and 3 hours PT3H5M indicates a period of time of 3 hours and 5 minutes
It's used by the SCORM RTE to measure the length of session times.
I've had a few goes but the code starts to look like spaghetti then I have to give up.
Since months have varying numbers of days and days can have varying
numbers of hours, there can be no proper answer.
You can get an approximate answer by assuming 30 or 30.6 days per month
and 24 hours per day.
Each paragraph below refers to one line of the following code paragraph.
Create an Object containing zero-duration components.
T, if present, serves only to discriminate months and minutes; so use it
to change the minute-identifier, if present, to Z.
P & T now have no use; remove them, if present.
Insert semicolon separators between the fields.
Split the fields at the semicolons.
For each field, use the final character to index in the Object the place
where the numeric part is then stored, as a Number.
Determine, to check, the interval in (approx) ISO 8601 form
Determine the Duration with assumed component lengths.
X = "P33Y14DT3H5M3. 7S" // test value
Obj = {Y:0, M:0, D:0, H:0, Z:0, S:0}
X = X.replace(/T(.*)M/, "T$1Z")
X = X.replace(/[PT]/g, "")
X = X.replace(/([A-Z])(\d)/g, "$1;$2")
X = X.split(';')
for (J in X) { T = X[J] ; Obj[T.charAt(T.leng th-1)] = parseFloat(X[J]) }
with (Obj) ISO = ((((Y*100+M)*10 0+D)*100+H)*100 +Z)*100+S
with (Obj) Dur = ((((Y*12+M)*30+ D)*24+H)*60+Z)* 60+S
The four conversions on X could be done in one statement.
If SCORM had followed the ISO 8601 standard for the representation of
duration, the job would have been considerably easier.
If your perplexing remark means seconds with 2 decimal places, then see
in the newsgroup FAQ or via below to convert variable Dur.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Dr John Stockton wrote: JRS: In article <42aed83a$0$229 27$5a62ac22@per-qv1-newsreader- 01.iinet.net.au >, dated Tue, 14 Jun 2005 23:15:21, seen in news:comp.lang. javascript, Andrew Poulos <ap*****@hotmai l.com> posted :
How do I convert a length of time, measured in seconds, into a "point in time" type time interval or what's represented as: time (second,10,2)
What the latter might mean is unclear to me. The format is:
P[yY][mM][dD][T[hH][mM][s[.s]S]] where:
y: The number of years (integer, >= 0, not restricted) m: The number of months (integer, >=0, not restricted) d: The number of days (integer, >=0, not restricted) h: The number of hours (integer, >=0, not restricted) n: The number of minutes (integer, >=0, not restricted) s: The number of seconds or fraction of seconds (real or integer, >=0, not restricted). If fractions of a second are used, SCORM further restricts the string to a maximum of 2 digits (e.g., 34.45 – valid, 34.45454545 – not valid). The character literals designators “P”,”Y”,”M”,”D” ,”T”,”H”,”M”,”S ” shall appear if the corresponding non-zero value is present.
Example: P1Y3M2DT3H indicates a period of time of 1 year, 3 months, 2 days and 3 hours PT3H5M indicates a period of time of 3 hours and 5 minutes
It's used by the SCORM RTE to measure the length of session times.
I've had a few goes but the code starts to look like spaghetti then I have to give up. Since months have varying numbers of days and days can have varying numbers of hours, there can be no proper answer.
You can get an approximate answer by assuming 30 or 30.6 days per month and 24 hours per day.
Each paragraph below refers to one line of the following code paragraph.
Create an Object containing zero-duration components.
T, if present, serves only to discriminate months and minutes; so use it to change the minute-identifier, if present, to Z.
P & T now have no use; remove them, if present.
Insert semicolon separators between the fields.
Split the fields at the semicolons.
For each field, use the final character to index in the Object the place where the numeric part is then stored, as a Number.
Determine, to check, the interval in (approx) ISO 8601 form
Determine the Duration with assumed component lengths.
X = "P33Y14DT3H5M3. 7S" // test value
Obj = {Y:0, M:0, D:0, H:0, Z:0, S:0} X = X.replace(/T(.*)M/, "T$1Z") X = X.replace(/[PT]/g, "") X = X.replace(/([A-Z])(\d)/g, "$1;$2") X = X.split(';') for (J in X) { T = X[J] ; Obj[T.charAt(T.leng th-1)] = parseFloat(X[J]) } with (Obj) ISO = ((((Y*100+M)*10 0+D)*100+H)*100 +Z)*100+S with (Obj) Dur = ((((Y*12+M)*30+ D)*24+H)*60+Z)* 60+S
The four conversions on X could be done in one statement.
If SCORM had followed the ISO 8601 standard for the representation of duration, the job would have been considerably easier.
If your perplexing remark means seconds with 2 decimal places, then see in the newsgroup FAQ or via below to convert variable Dur.
The representation I first mentioned should've been "timeinterv al
(second,10,2)" and it's supposedly an IEEE standard for the measurement
of time.
Sorry you the confusion. I'm was reading directly from the specification
which is, I guess by necessity, terse and cross-referenced to a variety
of tables, appendices etc. The standard also gives the option of precise
and less precise definitions of months and years.
As it is I've found a minimal solution: I'm just going to store the time
interval as a total number of seconds and not worry about breaking into
other time units. For example: PT123S is 123 seconds.
Andrew Poulos This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marcus |
last post by:
I am having some problems with trying to perform calculations on time
fields. Say I have a start time and an end time, 1:00:00 and 2:30:00
(on a 24 hour scale, not 12). I want to find the difference in minutes,
divide this result by a predefined size of interval, and make a loop
that runs this many times. For example, with an interval size of 15
minutes, it will return 6 blocks... I have this all working fine, but am
getting stuck on...
|
by: Andreas |
last post by:
Hi!
Is it possible to get a time event at a specific time, for instance
eight a'clock? My program is running in the background and is
minimized to the tray bar.
If not, is there a smooth way to accomplish this in a different way?
Best regards,
Andreas Lundgren
|
by: Holger Marzen |
last post by:
Say, we have uptimes from several servers:
Server up_from up_to
------ ------- -------
s1 0:00 8:00
s1 10:00 20:00
s1 22:00 24:00 (would better be a timestamp with 0:00 and next day)
s2 0:00 4:00
s2 6:00 23:00
|
by: Skybuck Flying |
last post by:
Hi,
I needed a method to determine if a point was on a line segment in 2D. So I
googled for some help and so far I have evaluated two methods.
The first method was only a formula, the second method was a piece of C code
which turned out to be incorrect and incomplete but by modifieing it would
still be usuable.
The first method was this piece of text:
|
by: HL |
last post by:
I am using VS 2005 Beta - C#
Problem: The Timer fires a few milliseconds before the actual Due-Time
Let's say a timer is created in the following manner:
System.Threading.Timer m_timer = null;
Let's declare a constant
Int32 m_TimePeriod = 10000;
| |
by: arief# |
last post by:
Dear all,
I'm sorry if this sounds stupid or have been talked about before.
Suppose I have a field in my table that's called duration with type
'time without timezone'. How do I do sum on this field based on another
field let say called dateofevent?
SQL: SELECT SUM(duration) FROM durtable GROUP BY dateofevent;
|
by: archana |
last post by:
Hi all,
I want to develop one windows service in which i want to provide some
scheduling facility.
What i want is to take start time frm one xml file and then at that
specified start time.
Which timer should i use in windows service to start particular process
at user specified time.
|
by: MathNewbie |
last post by:
Hi,
I'm trying to do get my head around some, probably basic, math
calculations. I checked some .net math libs, but the only thing I learn
from studying those is humility ;-).
Anyway, i have an array of points on a basic 2 dimensional axis. They
are all points of a sine shaped line. (not a perfect sine though, as
it's actually tide movement data that is roughly looking as a sine).
|
by: student4lifer |
last post by:
Hello,
I have 2 time fields dynamically generated in format "m/d/y H:m".
Could someone show me a good function to calculate the time interval
difference in minutes? I played with strtotime() but but that only
gave me difference in hours and only if the times were on the same day
(after wrapping with date() function). TIA
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: 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...
| |