Date manipulation: Difference between revisions

(5 intermediate revisions by 3 users not shown)
Line 1,308:
 
{{FormulaeEntry|page=https://formulae.org/?timeZone=America%2FNew_York&script=examples/Date_manipulation}}
 
'''Solution'''
 
'''Creating the initial time.''' Fōrmulæ can create a time in any time zone, however, it always displays them in the current timezone. In order to cause no confusion, in this example the current time zone has been set as America/New_York, which is EST.
 
[[File:Fōrmulæ - Date manipulation 01.png]]
 
[[File:Fōrmulæ - Date manipulation 02.png]]
 
'''Adding 12 hours.''' It is achieved adding to the time expression the desired number of milliseconds.
 
[[File:Fōrmulæ - Date manipulation 03.png]]
 
[[File:Fōrmulæ - Date manipulation 04.png]]
 
This is not a bug, the daylight saving time (in the America/New_York time zone), for 2009 started March 8 at 2:00 hrs, at which time clock is adjusted 1 hour later. It occurred between the 12 hour addition of our example. See [https://www.timeanddate.com/time/change/usa/new-york?year=2009 this page].
 
Note the ☀ symbol, indicating that the time is in daylight saving time (at the current time zone).
 
'''Showing results for other time zones.''' As it was said before, a time is always shown in current time zone, but a time can be formatted to different time zones.
 
If no time zone is specified, current time zone is used:
 
[[File:Fōrmulæ - Date manipulation 05.png]]
 
[[File:Fōrmulæ - Date manipulation 06.png]]
 
[[File:Fōrmulæ - Date manipulation 07.png]]
 
[[File:Fōrmulæ - Date manipulation 08.png]]
 
Let us use a different time zone:
 
[[File:Fōrmulæ - Date manipulation 09.png]]
 
[[File:Fōrmulæ - Date manipulation 10.png]]
 
[[File:Fōrmulæ - Date manipulation 11.png]]
 
[[File:Fōrmulæ - Date manipulation 12.png]]
 
Beside the time zone, a different locale can also be specified, in order to format the result in such that locale:
 
[[File:Fōrmulæ - Date manipulation 13.png]]
 
[[File:Fōrmulæ - Date manipulation 14.png]]
 
The components of a time expression can be obtained individually, even for a specific time zone:
 
[[File:Fōrmulæ - Date manipulation 15.png]]
 
[[File:Fōrmulæ - Date manipulation 16.png]]
 
=={{header|FutureBasic}}==
Line 1,744 ⟶ 1,796:
Langur currently uses the Go time package. Testing with Go 1.14.1 on Linux, the time package doesn't seem to parse "EST" correctly, and it seems to fail silently. Given these conditions, I use "-05:00" instead of "EST" in the input string.
 
{{works with|langur|0.10.1}}
<syntaxhighlight lang="langur">val .input = "March 7 2009 7:30pm -05:00"
val .iformat = "January 2 2006 3:04pm -07:00" # input format
val .formatoformat = "January 2 2006 3:04pm MST" # output format
 
val .d1 = toDateTimedatetime .input, .iformat
val .d2 = .d1 + dtdr/PT12H/
val .d3 = toDateTimedatetime .d2, "US/Arizona"
val .d4 = toDateTimedatetime .d2, ZLSzls
val .d5 = toDateTimedatetime .d2, "Z"
val .d6 = toDateTimedatetime .d2, "+02:30"
val .d7 = toDateTimedatetime .d2, "EST"
 
writeln "input string: ", .input
writeln "input format string: ", .iformat
writeln "output format string: ", .formatoformat
writeln()
 
writeln $"original: \.d1; (\.d1:dt.format oformat;)"
writeln $"+12 hours: \.d2; (\.d2:dt.format oformat;)"
writeln $"in Arizona: \.d3; (\.d3:dt.format oformat;)"
writeln $"in local time zone: \.d4; (\.d4:dt.format oformat;)"
writeln $"in UTC: \.d5; (\.d5:dt.format oformat;)"
writeln $"+02:30 time zone: \.d6; (\.d6:dt.format oformat;)"
writeln $"in EST: \.d7; (\.d7:dt.format oformat;)"</syntaxhighlight>
 
{{out}}
Line 1,921 ⟶ 1,972:
<syntaxhighlight lang="mathematica">dstr = "March 7 2009 7:30pm EST";
DateString[DatePlus[dstr, {12, "Hour"}], {"DayName", " ", "MonthName", " ", "Day", " ", "Year", " ", "Hour24", ":", "Minute", "AMPM"}]</syntaxhighlight>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">import "dateTime"
import "stringUtil"
 
months = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December",
]
 
date = "March 7 2009 7:30pm EST"
print "Original date/time : " + date
 
// change the date to standard format
items = date.split
month = months.indexOf(items[0]) + 1
day = items[1]
year = items[2]
time = items[3]
hour = time.split(":")[0].val
minute = time.split(":")[1][0:2]
pm = time.endsWith("pm")
if pm then hour = hour + 12
time = hour + ":" + minute
zone = items[4]
date = year + "-" + month + "-" + day + " " + time
 
// add 12 hours and display in original format
dval = dateTime.val(date) + 12*60*60
dfmt = "MMMM d yyyy h:mmtt"
date2 = dateTime.str(dval, dfmt) + " " + zone
print "12 hours later : " + date2
 
// change from EST to MST (2 hours earlier)
date3 = dateTime.str(dval - 2*60*60, dfmt) + " MST"
print "Adjusted to MST : " + date3</syntaxhighlight>
 
{{out}}
<pre>Original date/time : March 7 2009 7:30pm EST
12 hours later : March 8 2009 7:30am EST
Adjusted to MST : March 8 2009 5:30am MST
</pre>
 
=={{header|mIRC Scripting Language}}==
Line 3,256 ⟶ 3,349:
=={{header|Wren}}==
{{libheader|Wren-date}}
<syntaxhighlight lang="ecmascriptwren">import "./date" for Date
 
var fmt = "mmmm| |d| |yyyy| |H|:|MM|am| |zz|"
990

edits