Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
(define my-date (string->date "March 7 2009 7:30 pm EST"))
|
||||
→ Sun Mar 08 2009 01:30:00 GMT+0100 (CET)
|
||||
|
||||
(date-add! my-date (* 12 3600))
|
||||
→ Sun Mar 08 2009 13:30:00 GMT+0100 (CET)
|
||||
(string->date my-date)
|
||||
|
||||
(date->string my-date)
|
||||
→ "8/3/2009 13:30:00" ;; human localized, Paris time.
|
||||
86
Task/Date-manipulation/FreeBASIC/date-manipulation.freebasic
Normal file
86
Task/Date-manipulation/FreeBASIC/date-manipulation.freebasic
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
#include "vbcompat.bi"
|
||||
|
||||
Sub split (s As String, sepList As String, result() As String, removeEmpty As Boolean = False)
|
||||
If s = "" OrElse sepList = "" Then
|
||||
Redim result(0)
|
||||
result(0) = s
|
||||
Return
|
||||
End If
|
||||
Dim As Integer i, j, count = 0, empty = 0, length
|
||||
Dim As Integer position(Len(s) + 1)
|
||||
position(0) = 0
|
||||
|
||||
For i = 0 To len(s) - 1
|
||||
For j = 0 to Len(sepList) - 1
|
||||
If s[i] = sepList[j] Then
|
||||
count += 1
|
||||
position(count) = i + 1
|
||||
End If
|
||||
Next j
|
||||
Next i
|
||||
|
||||
Redim result(count)
|
||||
If count = 0 Then
|
||||
result(0) = s
|
||||
Return
|
||||
End If
|
||||
|
||||
position(count + 1) = len(s) + 1
|
||||
|
||||
For i = 1 To count + 1
|
||||
length = position(i) - position(i - 1) - 1
|
||||
result(i - 1 - empty) = Mid(s, position(i - 1) + 1, length)
|
||||
If removeEmpty Andalso CBool(length = 0) Then empty += 1
|
||||
Next
|
||||
|
||||
If empty > 0 Then Redim Preserve result(count - empty)
|
||||
End Sub
|
||||
|
||||
Function parseDate(dt As String, zone As String) As Double
|
||||
Dim result() As String
|
||||
split dt, " ", result(), True
|
||||
Dim As Long m, d, y, h, mn
|
||||
Dim am As Boolean
|
||||
Dim index As Integer
|
||||
Select Case Lcase(result(0))
|
||||
Case "january" : m = 1
|
||||
Case "february" : m = 2
|
||||
Case "march" : m = 3
|
||||
Case "april" : m = 4
|
||||
Case "may" : m = 5
|
||||
Case "june" : m = 6
|
||||
Case "july" : m = 7
|
||||
Case "august" : m = 8
|
||||
Case "september" : m = 9
|
||||
Case "october" : m = 10
|
||||
Case "november" : m = 11
|
||||
Case "december" : m = 12
|
||||
End Select
|
||||
d = ValInt(result(1))
|
||||
y = ValInt(result(2))
|
||||
result(3) = LCase(result(3))
|
||||
am = (Right(result(3), 2) = "am")
|
||||
index = Instr(result(3), ":")
|
||||
h = ValInt(Left(result(3), index - 1))
|
||||
If Not am Then
|
||||
h = h + 12
|
||||
If h = 24 Then h = 12
|
||||
End If
|
||||
mn = ValInt(Mid(result(3), index + 1, 2))
|
||||
zone = result(4)
|
||||
Return DateSerial(y, m, d) + TimeSerial(h, mn, 0)
|
||||
End Function
|
||||
|
||||
Dim zone As String
|
||||
Dim ds As Double = parseDate("March 7 2009 7:30pm EST", zone)
|
||||
Print "Original Date/Time : "; Format(ds, "mmmm d yyyy h:nnam/pm ") + " " + zone
|
||||
ds = DateAdd("h", 12, ds)
|
||||
Print "12 hours later : "; Format(ds, "mmmm d yyyy h:nnam/pm ") + " " + zone
|
||||
' add 5 hours to convert EST to UTC
|
||||
ds = DateAdd("h", 5, ds)
|
||||
Print "Equiv to Date/Time : "; Format(ds, "mmmm d yyyy h:nnam/pm ") + " UTC"
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
8
Task/Date-manipulation/FunL/date-manipulation.funl
Normal file
8
Task/Date-manipulation/FunL/date-manipulation.funl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import time.{TimeZone, Date, SimpleDateFormat, Hour}
|
||||
|
||||
pattern = SimpleDateFormat( 'MMMM d yyyy h:mma zzz' )
|
||||
date = pattern.parse( 'March 7 2009 7:30pm EST' )
|
||||
later = Date( date.getTime() + 12 Hour )
|
||||
println( pattern.format(later) ) // Eastern Daylight Time
|
||||
pattern.setTimeZone( TimeZone.getTimeZone('America/Los_Angeles') )
|
||||
println( pattern.format(later) ) // U.S. Pacific Time
|
||||
3
Task/Date-manipulation/Lasso/date-manipulation.lasso
Normal file
3
Task/Date-manipulation/Lasso/date-manipulation.lasso
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
local(date) = date('March 7 2009 7:30PM EST',-format='MMMM d yyyy h:mma z')
|
||||
#date->add(-hour = 24)
|
||||
#date->timezone = 'GMT'
|
||||
35
Task/Date-manipulation/Lingo/date-manipulation-1.lingo
Normal file
35
Task/Date-manipulation/Lingo/date-manipulation-1.lingo
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
----------------------------------------
|
||||
-- Returns string representation of given date object in YYYY-MM-DD hh:mm:ii format
|
||||
-- @param {date} dateObj
|
||||
-- @returns {string}
|
||||
----------------------------------------
|
||||
on dateToDateTimeString (dateObj)
|
||||
str = ""
|
||||
s = string(dateObj.year)
|
||||
if s.length<4 then put "0000".char[1..4-s.length] before s
|
||||
put s after str
|
||||
s = string(dateObj.month)
|
||||
if s.length<2 then s = "0"&s
|
||||
put s after str
|
||||
s = string(dateObj.day)
|
||||
if s.length<2 then put "0" before s
|
||||
put s after str
|
||||
sec = dateObj.seconds
|
||||
s = string(sec / 3600)
|
||||
sec = sec mod 3600
|
||||
if s.length<2 then put "0" before s
|
||||
put s after str
|
||||
s = string(sec / 60)
|
||||
sec = sec mod 60
|
||||
if s.length<2 then put "0" before s
|
||||
put s after str
|
||||
s = string(sec)
|
||||
if s.length<2 then put "0" before s
|
||||
put s after str
|
||||
put ":" after char 12 of str
|
||||
put ":" after char 10 of str
|
||||
put " " after char 8 of str
|
||||
put "-" after char 6 of str
|
||||
put "-" after char 4 of str
|
||||
return str
|
||||
end
|
||||
27
Task/Date-manipulation/Lingo/date-manipulation-2.lingo
Normal file
27
Task/Date-manipulation/Lingo/date-manipulation-2.lingo
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
dateStr = "March 7 2009 7:30pm EST"
|
||||
|
||||
-- parse string
|
||||
month = (offset(dateStr.word[1].char[1..3], "JanFebMarAprMayJunJulAugSepOctNovDec")-1)/3 + 1
|
||||
day = integer(dateStr.word[2])
|
||||
year = integer(dateStr.word[3])
|
||||
t = dateStr.word[4]
|
||||
if t.char[t.length-1..t.length]="pm" then dh = 12
|
||||
else dh = 0
|
||||
t = t.char[1..t.length-2]
|
||||
_player.itemDelimiter = ":"
|
||||
hour = integer(t.item[1])+dh
|
||||
minute = integer(t.item[2])
|
||||
tz = dateStr.word[5] -- unused
|
||||
|
||||
-- original date as date object
|
||||
dateObj = date(year,month,day)
|
||||
dateObj.seconds = hour*3600 + minute*60
|
||||
|
||||
-- add 12 hours
|
||||
sec = dateObj.seconds + 12*3600
|
||||
newDateObj = dateObj + sec / 86400
|
||||
newDateObj.seconds = sec mod 86400
|
||||
|
||||
-- show as YYYY-MM-DD hh:mm:ii string
|
||||
put dateToDateTimeString(newDateObj)
|
||||
-- "2009-03-08 07:30:00"
|
||||
6
Task/Date-manipulation/Nim/date-manipulation.nim
Normal file
6
Task/Date-manipulation/Nim/date-manipulation.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import posix, times
|
||||
|
||||
var ts: Ttm
|
||||
discard "March 7 2009 7:30pm EST".strptime("%B %d %Y %I:%M%p %Z", ts)
|
||||
ts.tmHour += 12
|
||||
echo ts.mktime
|
||||
10
Task/Date-manipulation/Phix/date-manipulation.phix
Normal file
10
Task/Date-manipulation/Phix/date-manipulation.phix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
include builtins\timedate.e
|
||||
set_timedate_formats({"Mmmm d yyyy h:mmpm tz"})
|
||||
timedate td = parse_date_string("March 7 2009 7:30pm EST")
|
||||
atom twelvehours = timedelta(hours:=12)
|
||||
td = adjust_timedate(td,twelvehours)
|
||||
?format_timedate(td)
|
||||
td = change_timezone(td,"ACDT") -- extra credit
|
||||
?format_timedate(td)
|
||||
td = adjust_timedate(td,timedelta(days:=31*4))
|
||||
?format_timedate(td)
|
||||
9
Task/Date-manipulation/Sidef/date-manipulation.sidef
Normal file
9
Task/Date-manipulation/Sidef/date-manipulation.sidef
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
var dt = frequire('DateTime::Format::Strptime')
|
||||
|
||||
var input = 'March 7 2009 7:30pm EST'
|
||||
input.sub!('EST', 'America/New_York')
|
||||
|
||||
say dt.strptime('%b %d %Y %I:%M%p %O', input) \
|
||||
.add(hours => 12) \
|
||||
.set_time_zone('America/Edmonton') \
|
||||
.format_cldr('MMMM d yyyy h:mma zzz')
|
||||
4
Task/Date-manipulation/jq/date-manipulation-1.jq
Normal file
4
Task/Date-manipulation/jq/date-manipulation-1.jq
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
"March 7 2009 7:30pm EST"
|
||||
| strptime("%B %d %Y %I:%M%p %Z")
|
||||
| .[3] += 12
|
||||
| mktime | strftime("%B %d %Y %I:%M%p %Z")
|
||||
1
Task/Date-manipulation/jq/date-manipulation-2.jq
Normal file
1
Task/Date-manipulation/jq/date-manipulation-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
"March 08 2009 07:30AM EST"
|
||||
Loading…
Add table
Add a link
Reference in a new issue