June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
30
Task/Date-manipulation/D/date-manipulation.d
Normal file
30
Task/Date-manipulation/D/date-manipulation.d
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import std.stdio;
|
||||
import std.format;
|
||||
import std.datetime;
|
||||
import std.algorithm;
|
||||
|
||||
enum months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
||||
|
||||
void main()
|
||||
{
|
||||
// input
|
||||
string date = "March 7 2009 7:30pm EST";
|
||||
|
||||
// parsing date string to integer values
|
||||
string month, md, tz;
|
||||
int day, year, hour, minute;
|
||||
date.formattedRead("%s %d %d %d:%d%s %s", &month, &day, &year, &hour, &minute, &md, &tz);
|
||||
int mon = cast (int) months.countUntil(month) + 1;
|
||||
|
||||
// convert to 24-hour
|
||||
if (md == "pm")
|
||||
hour += 12;
|
||||
|
||||
// create date from integer
|
||||
DateTime dt = DateTime(year, mon, day, hour, minute);
|
||||
|
||||
// output
|
||||
writeln(dt);
|
||||
writeln(dt + 12.hours);
|
||||
|
||||
}
|
||||
12
Task/Date-manipulation/Julia/date-manipulation.julia
Normal file
12
Task/Date-manipulation/Julia/date-manipulation.julia
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using Base.Dates
|
||||
|
||||
function main()
|
||||
dtstr = "March 7 2009 7:30pm" # Base.Dates doesn't handle "EST"
|
||||
cleandtstr = replace(dtstr, r"(am|pm)"i, "")
|
||||
dtformat = dateformat"U dd yyyy HH:MM"
|
||||
dtime = parse(DateTime, cleandtstr, dtformat) +
|
||||
Hour(12 * contains(dtstr, r"pm"i)) # add 12h for the pm
|
||||
println(Dates.format(dtime + Hour(12), dtformat))
|
||||
end
|
||||
|
||||
main()
|
||||
15
Task/Date-manipulation/Maple/date-manipulation-1.maple
Normal file
15
Task/Date-manipulation/Maple/date-manipulation-1.maple
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
twelve_hours := proc(str)
|
||||
local dt, zone;
|
||||
local months := ["January","February","March","April","May","June","July","August","September","October","November","December"];
|
||||
dt := StringTools:-ParseTime("%B %d %Y %l:%M%p", str);
|
||||
zone := StringTools:-RegSplit(" ", str)[-1];
|
||||
dt := Date(dt:-year, dt:-month, dt:-monthDay, dt:-hour, dt:-minute, timezone = zone);
|
||||
dt := dt + 12 * Unit(hours);
|
||||
printf("%s %d %d ", months[Month(dt)], DayOfMonth(dt), Year(dt));
|
||||
if (HourOfDay(dt) >= 12) then
|
||||
printf("%d:%dpm ", HourOfDay(dt)-12, Minute(dt));
|
||||
else
|
||||
printf("%d:%dam ", HourOfDay(dt), Minute(dt));
|
||||
end if;
|
||||
printf(TimeZone(dt));
|
||||
end proc;
|
||||
3
Task/Date-manipulation/Maple/date-manipulation-2.maple
Normal file
3
Task/Date-manipulation/Maple/date-manipulation-2.maple
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
twelve_hours("March 7 2009 7:30pm EST");
|
||||
twelve_hours("March 2 2009 0:10am WET");
|
||||
twelve_hours("March 2 2009 6:30am AST");
|
||||
6
Task/Date-manipulation/Red/date-manipulation.red
Normal file
6
Task/Date-manipulation/Red/date-manipulation.red
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
d: 07-Mar-2009/19:30 + 12:00
|
||||
print d
|
||||
8-Mar-2009/7:30:00
|
||||
d/timezone: 1
|
||||
print d
|
||||
8-Mar-2009/8:30:00+01:00
|
||||
29
Task/Date-manipulation/Ring/date-manipulation.ring
Normal file
29
Task/Date-manipulation/Ring/date-manipulation.ring
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# Project : Date manipulation
|
||||
# Date : 2018/02/14
|
||||
# Author : Gal Zsolt (~ CalmoSoft ~)
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
load "stdlib.ring"
|
||||
dateorigin = "March 7 2009 7:30pm EST"
|
||||
monthname = "January February March April May June July August September October November December"
|
||||
for i = 1 to 12
|
||||
if dateorigin[1] = monthname[i]
|
||||
monthnum = i
|
||||
ok
|
||||
next
|
||||
thedate = str2list(substr(dateorigin, " ", nl))
|
||||
t = thedate[4]
|
||||
t1 = substr(t,"pm", "")
|
||||
t2 = substr(t1,":",".")
|
||||
t3 = number(t2)
|
||||
if right(t,2) = "pm"
|
||||
t3 = t3+ 12
|
||||
ok
|
||||
ap = "pm"
|
||||
d = "07/03/2009"
|
||||
if t3 + 12 > 24
|
||||
d = adddays("07/03/2009",1)
|
||||
ap = "am"
|
||||
ok
|
||||
see "Original - " + dateorigin + nl
|
||||
see "Manipulated - " + d + " " + t1 + ap + nl
|
||||
Loading…
Add table
Add a link
Reference in a new issue