Convert String to Date and Add ±N Hours

Salih Dincer salihdb at hotmail.com
Wed Nov 8 04:46:28 UTC 2023


On Saturday, 4 November 2023 at 21:10:38 UTC, Steven 
Schveighoffer wrote:
> On Saturday, 4 November 2023 at 18:11:53 UTC, Vahid wrote:
>> Hi,
>>
>> I have a date string with the format of "2023-11-04 23:10:20". 
>> I want to convert this string to Date object and also, add ±N 
>> hours to it. For example:
>>
>> `"2023-11-04 23:10:20" + "+2:00" = "2023-11-05 01:10:20"`
>> `"2023-11-04 23:10:20" + "-2:30" = "2023-11-05 20:40:20"`
>>
>> How can I do this?
>
> Parse the date. There is a nice package on code.dlang.org that 
> is for date parsing: https://code.dlang.org/packages/dateparser
>
> -Steve

I couldn't get it to work, can you help me with this? I think the 
error is related to line 803 in the package.d file:

> import containers.dynamicarray : DynamicArray;

This means it is dependent on containers by Dlang Community.

This was installed it: 
https://github.com/dlang-community/containers

However I get these errors:

> dmd -w -of"bench.a" "bench.d" containers/package.d 
> dateparser/package.d
>
> /usr/bin/ld: bench.o:(.data.rel.ro+0x60): undefined reference 
> to `_D10containers12dynamicarray12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x78): undefined reference 
> to `_D10containers8internal4node12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x120): undefined reference 
> to `_D10containers12cyclicbuffer12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x128): undefined reference 
> to `_D10containers12dynamicarray12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x130): undefined reference 
> to `_D10containers7hashmap12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x138): undefined reference 
> to `_D10containers7hashset12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x140): undefined reference 
> to `_D10containers11openhashset12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x148): undefined reference 
> to `_D10containers5slist12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x150): undefined reference 
> to `_D10containers7treemap12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x158): undefined reference 
> to `_D10containers5ttree12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x160): undefined reference 
> to `_D10containers12unrolledlist12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x1c8): undefined reference 
> to `_D10dateparser9timelexer12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x1d0): undefined reference 
> to `_D10dateparser3ymd12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x1d8): undefined reference 
> to `_D10dateparser11parseresult12__ModuleInfoZ'
> /usr/bin/ld: bench.o:(.data.rel.ro+0x1e0): undefined reference 
> to `_D10dateparser10parserinfo12__ModuleInfoZ'
> /usr/bin/ld: bench.o: in function `_Dmain':
dateparser/package.d:(.text._Dmain[_Dmain]+0x1e): undefined 
reference to `_D10dateparser10parserinfo10ParserInfo7__ClassZ'
> /usr/bin/ld: dateparser/package.d:(.text._Dmain[_Dmain]+0x2f): 
> undefined reference to 
> `_D10dateparser10parserinfo10ParserInfo6__ctorMFNfbbZCQBzQBqQBh'
> /usr/bin/ld: bench.o: in function 
> `_D3std4conv__T6toImplTEQv8datetime4date5MonthTSQBt8typecons__T8NullableTiViN2147483648ZQzZQCyFQBwZQCy':
dateparser/package.d:
> .
> .
> .
> collect2: error: ld returned 1 exit status
> Error: linker exited with status 1

SDB at 79


More information about the Digitalmars-d-learn mailing list